Ну лови, родной, мне не жалко. Только сдаеццо мне, что засыпесси ты с эдаким кодом, эх, засыпесси...
class DicEntry : IComparable, IEquatable
{
private int popularity = 0;
private string word;
public int Popularity { get => popularity; }
public string Word { get => word; }
public DicEntry(string _Word, int _Popularity)
{
word = _Word;
popularity = _Popularity;
}
public int CompareTo(object? obj)
{
if (!(obj is DicEntry))
throw new NotImplementedException();
return popularity.CompareTo(((DicEntry)obj).popularity);
}
public bool Equals(DicEntry? other)
{
return popularity.Equals(other.popularity) && word.Equals(other.word);
}
}
class MyDic: List
{
private int autocomplete(string s) => IndexOf(this.Where(x => x.Word.StartsWith(s)).Max()) + 1;
public void ProcessCommands(int _Count)
{
string t = string.Empty;
for(int i = 0; i < _Count; i++)
{
char[] c = Console.ReadLine().ToCharArray();
if (c[0] == '+' || c[0] == '-')
{
t = (c[0] == '+') ? t + c.Last().ToString() : t.Substring(0, t.Length - 1);
Console.WriteLine(autocomplete(t));
}
}
}
}
internal class Program
{
static MyDic GetList(int _Count)
{
MyDic Result = new MyDic();
for (int i = 0; i < _Count; i++)
{
string[] s = Console.ReadLine().Split(' ');
Result.Add(new DicEntry(s[0], int.Parse(s[1])));
}
return Result;
}
static void Main(string[] args)
{
int[] nq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
MyDic Dic = GetList(nq[0]);
Dic.ProcessCommands(nq[1]);
}
}