Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace KR
- {
- class Program
- {
- static Random rnd = new Random();
- static string MakeRndString(int N)
- {
- char[] str = new char[N];
- for (int i = 0; i < N; i++)
- {
- str[i] = (char)rnd.Next(97, 123);
- }
- return string.Join("", str);
- }
- static char MostFrequentSearcher(char[] arr)
- {
- char[] buff = arr;
- Array.Sort(buff);
- int max = 1, counter = 0;
- char count = buff[0], maxChar = buff[0];
- for (int i = 0; i < buff.Length; i++)
- {
- if (count == buff[i])
- {
- counter++;
- continue;
- }
- count = buff[i];
- if (max < counter)
- {
- maxChar = buff[i - 1];
- max = counter;
- }
- }
- return maxChar;
- }
- static char[] MakeNewArr(char[] arr)
- {
- char[] buff = arr;
- //В разработке
- return buff;
- }
- static bool Continue(string pass)
- {
- Console.WriteLine($"Хотите продолжить, введите: [ {pass} ]\n");
- return Console.ReadLine() == pass;
- }
- static bool Continue(ConsoleKey pass)
- {
- Console.WriteLine($"Хотите продолжить, нажмите: [ {pass.ToString()} ]\n");
- return Console.ReadKey().Key == pass;
- }
- static void ReadInt(out int num, int min, int max)
- {
- while (!int.TryParse(Console.ReadLine(), out num)
- || num > max || num < min)
- {
- if (num > max)
- {
- Console.WriteLine("Слишком большое число. Давай заново");
- }
- else if (num < min)
- {
- Console.WriteLine("Слишком маленькое число. Давай заново");
- }
- else
- {
- Console.WriteLine("Это и близко не int. Давай заново");
- }
- }
- }
- static void Main(string[] args)
- {
- do
- {
- int N;
- Console.WriteLine($"Введите число в промежутке (0; +бесконечность)");
- ReadInt(out N, 1, int.MaxValue);
- string str = MakeRndString(N);
- Console.WriteLine($"Сгенерированная строка:\t\t{str}");
- Console.Write($"Полученный массив символов:\t");
- char[] chArr = str.ToCharArray();
- foreach (var item in chArr)
- {
- Console.Write(item + " ");
- }
- Console.WriteLine($"\nСамый частый элемент:\t\t{MostFrequentSearcher(chArr)}\n");
- } while (Continue(ConsoleKey.Enter));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement