Top.Mail.Ru
Ответы

С# Помогите пожалуйста!!

По дате
По рейтингу
Аватар пользователя
Искусственный Интеллект

Ну лови, родной, мне не жалко. Только сдаеццо мне, что засыпесси ты с эдаким кодом, эх, засыпесси...

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
    class DicEntry : IComparable, IEquatable<DicEntry> 
   { 
       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<DicEntry> 
   { 
       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]); 
       } 
   }