Advertisement
kadyr

Untitled

Jun 17th, 2021
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. public static void Main(string[] args)
  2.         {
  3.             char[] numbers = new char[4] { '2', '3', '4', '5' };
  4.             FileStream fin;
  5.             string s;
  6.             int i;
  7.            
  8.             try
  9.             {
  10.                 fin = new FileStream("test2.txt", FileMode.Open);
  11.             }
  12.             catch (IOException exc)
  13.             {
  14.                 Console.WriteLine("Ошибка открытия файла:\n" + exc.Message);
  15.                 Console.ReadKey();
  16.                 return;
  17.             }
  18.  
  19.             StreamReader fstr_in = new StreamReader(fin, System.Text.Encoding.GetEncoding(1251));
  20.  
  21.             try
  22.             {
  23.  
  24.                 while ((s = fstr_in.ReadLine()) != null)
  25.                 {
  26.                     //Здесь мы парсим строки
  27.                     //s - целая строка
  28.                     int[,] numbers_pluser = new int[4,20]; // 4 - кол-во предметов 20 - кол-во учеников
  29.                     for(int y=0; y < 3; y++)
  30.                     {
  31.                         //t - один символ из строки
  32.                         foreach (var t in s)
  33.                         {
  34.                             int counterX = 0;
  35.                             if (numbers.Contains(t))
  36.                             {
  37.                                 numbers_pluser[counterX, y] = int.Parse(t.ToString());
  38.                                 counterX += 1;
  39.                             }
  40.                         }
  41.                     }
  42.                    
  43.                 }
  44.             }
  45.             catch (IOException exc)
  46.             {
  47.  
  48.                 Console.WriteLine("Ошибка ввода-вывода:\n" + exc.Message);
  49.  
  50.             }
  51.             finally
  52.             {
  53.                 fstr_in.Close();
  54.             }
  55.             Console.ReadLine();
  56.  
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement