Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Gleb_Felyust_1911_var1
- {
- class Program
- {
- static int[] GenerateArray(int N)
- {
- int[] arr = new int[N];
- for (int i = 0; i < N; i++)
- {
- while (!int.TryParse(Console.ReadLine(), out arr[i]) || arr[i] < Math.Pow(-10, 5) || arr[i] > Math.Pow(10, 5))
- {
- Console.WriteLine("Ошибка ввода");
- }
- }
- return arr;
- }
- static int Array_size()
- {
- int N;
- while (!int.TryParse(Console.ReadLine(), out N) || N < 1 || N > Math.Pow(10,4))
- {
- Console.WriteLine("Ошибка ввода");
- }
- return N;
- }
- static string WriteToColumn(int[] arr)
- {
- string st = "";
- for (int i = 0; i < arr.Length; i++)
- {
- st += Convert.ToString(arr[i]) + "\n";
- }
- return st;
- }
- static void Main(string[] args)
- {
- try
- {
- // Заполение файла input.txt.
- int n = Array_size();
- int[] arr = GenerateArray(n);
- File.WriteAllText("input.txt", WriteToColumn(arr));
- int max = 0;
- string[] readText = File.ReadAllLines("input.txt");
- foreach (string s in readText)
- {
- if (Convert.ToInt32(s) > max)
- {
- max = Convert.ToInt32(s);
- }
- }
- int counter = 0;
- foreach (string t in readText)
- {
- if (t == Convert.ToString(max))
- {
- counter += 1;
- }
- }
- Console.WriteLine(counter);
- File.WriteAllText("output.txt", Convert.ToString(counter));
- }
- catch (Exception ex)
- {
- Console.WriteLine("Ошибка:" + ex);
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement