Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Gleb_Felyust_1911_var1
  5. {
  6.     class Program
  7.     {
  8.         static int[] GenerateArray(int N)
  9.         {
  10.             int[] arr = new int[N];
  11.             for (int i = 0; i < N; i++)
  12.             {
  13.                 while (!int.TryParse(Console.ReadLine(), out arr[i]) || arr[i] < Math.Pow(-10, 5) || arr[i] > Math.Pow(10, 5))
  14.                 {
  15.                     Console.WriteLine("Ошибка ввода");
  16.                 }
  17.             }
  18.             return arr;
  19.         }
  20.         static int Array_size()
  21.         {
  22.             int N;
  23.             while (!int.TryParse(Console.ReadLine(), out N) || N < 1 || N > Math.Pow(10,4))
  24.             {
  25.                 Console.WriteLine("Ошибка ввода");
  26.             }
  27.             return N;
  28.         }
  29.         static string WriteToColumn(int[] arr)
  30.         {
  31.             string st = "";
  32.             for (int i = 0; i < arr.Length; i++)
  33.             {
  34.                 st += Convert.ToString(arr[i]) + "\n";
  35.             }
  36.             return st;
  37.         }
  38.         static void Main(string[] args)
  39.         {
  40.             try
  41.             {
  42.                 // Заполение файла input.txt.
  43.                 int n = Array_size();
  44.                 int[] arr = GenerateArray(n);
  45.                 File.WriteAllText("input.txt", WriteToColumn(arr));
  46.                 int max = 0;
  47.                 string[] readText = File.ReadAllLines("input.txt");
  48.                 foreach (string s in readText)
  49.                 {
  50.                     if (Convert.ToInt32(s) > max)
  51.                     {
  52.                         max = Convert.ToInt32(s);
  53.                     }
  54.                 }
  55.                 int counter = 0;
  56.                 foreach (string t in readText)
  57.                 {
  58.                     if (t == Convert.ToString(max))
  59.                     {
  60.                         counter += 1;
  61.                     }
  62.                 }
  63.                 Console.WriteLine(counter);
  64.                 File.WriteAllText("output.txt", Convert.ToString(counter));
  65.             }
  66.             catch (Exception ex)
  67.             {
  68.                 Console.WriteLine("Ошибка:" + ex);
  69.             }
  70.             Console.ReadLine();
  71.  
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement