Zneeky

Вар 1. Зад 2 LetterHistogram

Nov 20th, 2021 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5.  
  6.  
  7. namespace N_redica
  8.  
  9. {
  10.  
  11.     class Program
  12.  
  13.     {
  14.  
  15.         static void Main(string[] args)
  16.  
  17.         {
  18.  
  19.             string inputLine;
  20.             Console.OutputEncoding = Encoding.UTF8;
  21.             Console.InputEncoding = Encoding.UTF8;
  22.  
  23.             int countDigits = 0;
  24.             int countWordsSum = 0;
  25.             //char[] letters = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
  26.             SortedDictionary<char, int> histogram = new SortedDictionary<char, int>();
  27.  
  28.             do
  29.             {
  30.  
  31.                 inputLine = Console.ReadLine();
  32.  
  33.                 inputLine.ToLower();
  34.                 string[] words = inputLine.Split(new char[] {',', '.', ' ',';',':','?','!','-','(',')','"','/'}, StringSplitOptions.RemoveEmptyEntries);
  35.                 char[] charArr = inputLine.ToCharArray();
  36.  
  37.                 foreach(var item in charArr)
  38.                 {
  39.                     if (item>=97 && item<=122)
  40.                     {
  41.                         if (histogram.ContainsKey(item) )
  42.                         {
  43.                             histogram[item]++;
  44.                         }
  45.                         else
  46.                         {
  47.                             histogram[item]=1;
  48.                         }
  49.                        
  50.                     }
  51.                    
  52.  
  53.  
  54.  
  55.                     if (item <= 57 && item>=48)
  56.                     {
  57.                         countDigits += 1;
  58.                     }
  59.                 }
  60.                 /* foreach(var item in words)
  61.                 {
  62.                     Console.Write(item+" ");
  63.                 }
  64.                */
  65.                 countWordsSum += words.Length;
  66.  
  67.             } while (!inputLine.Equals(""));
  68.             Console.WriteLine("Total words in the text: " + countWordsSum);
  69.             Console.WriteLine("Total digits in the text: " + countDigits);
  70.  
  71.             foreach (KeyValuePair<char, int> pair in histogram)
  72.             {
  73.                 if (pair.Value == 1)
  74.                 {
  75.                     Console.WriteLine("{0} occurred {1} time", pair.Key, pair.Value);
  76.                 }
  77.                 else
  78.                 {
  79.                     Console.WriteLine("{0} occurred {1} times", pair.Key, pair.Value);
  80.                 }
  81.                
  82.             }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.         }
  90.  
  91.     }
  92.  
  93. }
  94.  
Add Comment
Please, Sign In to add comment