Advertisement
StreetKatya

Денис

Nov 13th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.08 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Slovar
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             //SortedDictionary<string, string> dict = new SortedDictionary<string, string>();
  15.             //dict.Add("byte", "byte");
  16.             SortedSet<string> dict = new SortedSet<string>();
  17.             //List<string> dict = new List<string>();
  18.             dict.Add("byte");
  19.             StringBuilder result = new StringBuilder();
  20.             using (var sr = new StreamReader("input.txt"))
  21.             {
  22.                 while (!sr.EndOfStream)
  23.                 {
  24.                     string str = sr.ReadLine();
  25.                     //Console.WriteLine(str);
  26.                     if (str[0] == '+')
  27.                     {
  28.                         string temp = str.Substring(1, str.Length - 1);
  29.                         if(!dict.Contains(temp))
  30.                         {
  31.                             dict.Add(temp);
  32.                         }
  33.                     }
  34.                     else //?
  35.                     {
  36.                         string temp = str.Substring(1, str.Length - 1);
  37.                         int countSearch = 0;
  38.                         result.AppendLine(temp);
  39.                         bool flag = false;
  40.                         foreach (string item in dict)
  41.                         {
  42.                             if(countSearch == 20)
  43.                             {
  44.                                 break;
  45.                             }
  46.                             if (item.Contains(temp))
  47.                             {
  48.                                 int countLetter = 0;
  49.                                 for (int i = 0; i < temp.Length; i++)
  50.                                 {
  51.                                     if (item[i] == temp[i])
  52.                                     {
  53.                                         countLetter++;
  54.                                     }
  55.                                     else break;
  56.                                 }
  57.                                 if(countLetter == temp.Length)
  58.                                 {
  59.                                     result.AppendLine(item);
  60.                                     countSearch++;
  61.                                     flag = true;
  62.                                 }
  63.                                 else if(flag == true)
  64.                                 {
  65.                                     break;
  66.                                 }
  67.                             }
  68.                         }
  69.                         //for (int i = 0; i < dict.Count; i++)
  70.                         //{
  71.  
  72.                         //    int count = 0;
  73.                         //    bool flagLetter = false;
  74.                         //    for (int j = 0; j < temp.Length; j++)
  75.                         //    {
  76.                         //        if (dict[i][j] == temp[j])
  77.                         //        {
  78.                         //            flagLetter = true;
  79.                         //            count++;
  80.                         //            if (count == temp.Length)
  81.                         //            {
  82.                         //                countSearch++;
  83.                         //                result.AppendLine(dict[i]);
  84.                         //            }
  85.                         //        }
  86.                         //        else break;
  87.                         //        if (countSearch == 20)
  88.                         //        {
  89.                         //            break;
  90.                         //        }
  91.                         //        if(dict[i][j] != temp[j] && flagLetter == true)
  92.                         //        {
  93.                         //            break;
  94.                         //        }
  95.                         //    }
  96.                         //}
  97.                     }
  98.                 }
  99.             }
  100.             using(var sw = new StreamWriter("output.txt"))
  101.             {
  102.                 sw.Write(result);
  103.             }
  104.         }
  105.     }
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement