Advertisement
AIwinter

oop

Feb 10th, 2023
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. namespace ConsoleApp10
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             string path = "file.txt";z
  8.             string text = "root startsart faaaasast";
  9.             string smax; //slovo
  10.             string s = "";
  11.             int kmax = 0;    //chetchik
  12.             int km = 0;
  13.             int k = 0;
  14.             char[] g = { 'a', 'e', 'i', 'o', 'u', 'y' };
  15.             char[] consonants = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z' };
  16.            
  17.  
  18.             // полная перезапись файла
  19.             using (StreamWriter writer = new StreamWriter(path, false))
  20.             {
  21.                 string ntxt = "";
  22.                 foreach (char c in text)
  23.                 {
  24.                     if (g.Contains(c) || consonants.Contains(c) || c == ' ')
  25.                     {
  26.                         ntxt += c;
  27.                     }
  28.                 }
  29.                 writer.WriteLine(ntxt);
  30.             }
  31.  
  32.             using (StreamReader reader = new StreamReader(path))
  33.             {
  34.                 while (reader.Peek() != -1) //peek смотрит какой символ впереди. если конец файла - возвращает -1
  35.                 {
  36.                     char a = (char)reader.Read(); //считываем и смещаем на след символ
  37.  
  38.                     if (a == ' ')
  39.                     {
  40.                         if (km > kmax)
  41.                         {
  42.                             kmax = km;
  43.                             smax = s;
  44.                             k = 0;
  45.                         }
  46.                         continue;
  47.                     }
  48.                     s += a;
  49.  
  50.                     if (!g.Contains(a))
  51.                     {
  52.                         k++;
  53.                         if (k > km)
  54.                         {
  55.                             km = k;
  56.                         }
  57.  
  58.                     }
  59.  
  60.                     else
  61.                     {
  62.                         k = 0;
  63.                     }
  64.                 }
  65.  
  66.                 Console.WriteLine(s);
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement