Advertisement
semkaegor4ik

IX II 19

Oct 27th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. class Program
  8. {
  9.    
  10.  
  11.     static int Main()
  12.     {
  13.         File.WriteAllText("output.txt", String.Empty);
  14.         string line;
  15.         using (StreamReader fileIn = new StreamReader("input.txt"))
  16.             line = fileIn.ReadLine();
  17.         bool flag = true;
  18.         foreach (char elem in line)
  19.         {
  20.             if (Char.IsLetter(elem))
  21.             {
  22.                 flag = false;
  23.                 break;
  24.             }
  25.         }
  26.         if (flag)
  27.         {
  28.             Console.WriteLine("В файле нету букв");
  29.             return 0;
  30.         }
  31.         Console.WriteLine("Введите нужную букву");
  32.         char ch = char.Parse(Console.ReadLine());
  33.         while(!Char.IsLetter(ch))
  34.         {
  35.             Console.WriteLine("Вы ошиблись, введите букву");
  36.             ch = char.Parse(Console.ReadLine());
  37.         }
  38.         bool s = true;
  39.         foreach (char elem in line)
  40.         {
  41.             if (elem==ch)
  42.             {
  43.                 s = false;
  44.                 break;
  45.             }
  46.         }
  47.         if (s)
  48.         {
  49.             Console.WriteLine("В файле нету нужной буквы");
  50.             return 0;
  51.         }
  52.         using (StreamWriter fileOut = new StreamWriter("output.txt", false))
  53.         {
  54.             for (int i = 0; i < line.Length - 1; i++)
  55.             {
  56.                 if (line[i] == ch)
  57.                 {
  58.                     fileOut.Write("{0} ", line[i + 1]);
  59.                 }
  60.             }
  61.         }
  62.  
  63.         return 0;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement