Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp5
  7. {
  8.     class Program
  9.     {
  10.         static Random rnd = new Random();
  11.  
  12.         static public char MostFindedChar(string str)
  13.         {
  14.             int[] arr = new int['z'-'a'+1];
  15.  
  16.             for (int i = 0; i < str.Length; i++)
  17.             {
  18.                 arr['a' - str[i]]++;
  19.             }
  20.  
  21.             int maxIndex = 0;
  22.  
  23.             for (int i = 0; i < arr.Length; i++)
  24.             {
  25.                 if (arr[i] > arr[maxIndex])
  26.                     maxIndex = i;
  27.             }
  28.  
  29.             return (char)(arr[maxIndex] + 'a');
  30.         }
  31.  
  32.         static public char[] ArrayGen()
  33.         {
  34.             List<char> list = new List<char>();
  35.             int k;
  36.             do
  37.             {
  38.                 Console.WriteLine("Введите к: ");
  39.             } while (!int.TryParse(Console.ReadLine(), out k));
  40.  
  41.             File.AppendAllText("../../log.txt", $"k = {k}\n");
  42.  
  43.             for (int i = 'a'; i <= 'z'; i++)
  44.             {
  45.                 if(i % k == 0)
  46.                     list.Add((char)i);
  47.             }
  48.  
  49.             return list.ToArray();
  50.         }
  51.  
  52.         static public int FindCharsCount(string str, char ch1, char ch2)
  53.         {
  54.             int count = 0;
  55.  
  56.             for (int i = 0; i < str.Length; i++)
  57.             {
  58.                 if (str[i] >= ch1 && str[i] <= ch2)
  59.                     count++;
  60.             }
  61.  
  62.             return count;
  63.         }
  64.  
  65.         static public void CharsCount(string str)
  66.         {
  67.             int[] arr = new int['z' - 'a' + 1];
  68.  
  69.             for (int i = 0; i < str.Length; i++)
  70.             {
  71.                 arr['a' - str[i]]++;
  72.             }
  73.  
  74.             for (int i = 0; i < arr.Length; i++)
  75.             {
  76.                 if(arr[i] == 0)
  77.                     continue;
  78.  
  79.                 Console.Write(i + 'a' + ": " + arr[i]);
  80.             }
  81.         }
  82.  
  83.         static void Main(string[] args)
  84.         {
  85.             int n;
  86.             try
  87.             {
  88.                 n = int.Parse(Console.ReadLine());
  89.  
  90.                 if(n < 1)
  91.                     throw new ArgumentException("Длина была меньше 1.");
  92.             }
  93.             catch (Exception e)
  94.             {
  95.                 Console.WriteLine(e.Message);
  96.                 return;
  97.             }
  98.  
  99.             string str = "";
  100.             for (int i = 0; i < n; i++)
  101.             {
  102.                 str += (char)rnd.Next('a', 'z' + 1);
  103.             }
  104.  
  105.             char[] arr = str.ToCharArray();
  106.  
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement