Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Slovar
- {
- class Program
- {
- static void Main(string[] args)
- {
- //SortedDictionary<string, string> dict = new SortedDictionary<string, string>();
- //dict.Add("byte", "byte");
- SortedSet<string> dict = new SortedSet<string>();
- //List<string> dict = new List<string>();
- dict.Add("byte");
- StringBuilder result = new StringBuilder();
- using (var sr = new StreamReader("input.txt"))
- {
- while (!sr.EndOfStream)
- {
- string str = sr.ReadLine();
- //Console.WriteLine(str);
- if (str[0] == '+')
- {
- string temp = str.Substring(1, str.Length - 1);
- if(!dict.Contains(temp))
- {
- dict.Add(temp);
- }
- }
- else //?
- {
- string temp = str.Substring(1, str.Length - 1);
- int countSearch = 0;
- result.AppendLine(temp);
- bool flag = false;
- foreach (string item in dict)
- {
- if(countSearch == 20)
- {
- break;
- }
- if (item.Contains(temp))
- {
- int countLetter = 0;
- for (int i = 0; i < temp.Length; i++)
- {
- if (item[i] == temp[i])
- {
- countLetter++;
- }
- else break;
- }
- if(countLetter == temp.Length)
- {
- result.AppendLine(item);
- countSearch++;
- flag = true;
- }
- else if(flag == true)
- {
- break;
- }
- }
- }
- //for (int i = 0; i < dict.Count; i++)
- //{
- // int count = 0;
- // bool flagLetter = false;
- // for (int j = 0; j < temp.Length; j++)
- // {
- // if (dict[i][j] == temp[j])
- // {
- // flagLetter = true;
- // count++;
- // if (count == temp.Length)
- // {
- // countSearch++;
- // result.AppendLine(dict[i]);
- // }
- // }
- // else break;
- // if (countSearch == 20)
- // {
- // break;
- // }
- // if(dict[i][j] != temp[j] && flagLetter == true)
- // {
- // break;
- // }
- // }
- //}
- }
- }
- }
- using(var sw = new StreamWriter("output.txt"))
- {
- sw.Write(result);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement