Advertisement
Lyubohd

TU_02

May 14th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1. namespace Problem_02
  2. {
  3.     using System;
  4.  
  5.     public class StartUp
  6.     {
  7.         public static void Main()
  8.         {
  9.             //Прочитаме входа
  10.             string input = Console.ReadLine();
  11.  
  12.             //Извикваме функцията за броене на думите в текста
  13.             WordsCount(input);
  14.             //Извикваме функцията за смяна на главните с малки букви
  15.             ToLower(input);
  16.             //Извикваме функцията за броене на числата в текста
  17.             DigitCount(input);
  18.         }
  19.  
  20.         //Функция за броене на думите
  21.         public static void WordsCount(String input)
  22.         {
  23.             string[] words = input.Split(new char[] { ' ', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
  24.  
  25.             int wordCount = words.Length;
  26.             Console.WriteLine("Броят на думите в текста са: " + wordCount);
  27.         }
  28.  
  29.         //Функция за броене на цифрите
  30.         public static void DigitCount(String input)
  31.         {
  32.             int zero = 0;
  33.             int one = 0;
  34.             int two = 0;
  35.             int three = 0;
  36.             int four = 0;
  37.             int five = 0;
  38.             int six = 0;
  39.             int seven = 0;
  40.             int eight = 0;
  41.             int nine = 0;
  42.             //За всеки символ от текста проверяваме дали е цифра
  43.             //за всяко съвпадение увеличаваме броя на конкретната цифра
  44.             foreach (var character in input)
  45.             {
  46.                 switch (character)
  47.                 {
  48.                     case '0':
  49.                         zero++;
  50.                         break;
  51.                     case '1':
  52.                         one++;
  53.                         break;
  54.                     case '2':
  55.                         two++;
  56.                         break;
  57.                     case '3':
  58.                         three++;
  59.                         break;
  60.                     case '4':
  61.                         four++;
  62.                         break;
  63.                     case '5':
  64.                         five++;
  65.                         break;
  66.                     case '6':
  67.                         six++;
  68.                         break;
  69.                     case '7':
  70.                        seven++;
  71.                         break;
  72.                     case '8':
  73.                         eight++;
  74.                         break;
  75.                     case '9':
  76.                         nine++;
  77.                         break;
  78.                     default:
  79.                         break;
  80.                 }
  81.             }
  82.             Console.WriteLine("Числата които се срещат в текста са:");
  83.             Console.WriteLine("Нула: " + zero);
  84.             Console.WriteLine("Едно: " + one);
  85.             Console.WriteLine("Две: " + two);
  86.             Console.WriteLine("Три: " + three);
  87.             Console.WriteLine("Четири: " + four);
  88.             Console.WriteLine("Пет: " + five);
  89.             Console.WriteLine("Шест: " + six);
  90.             Console.WriteLine("Седем: " + seven);
  91.             Console.WriteLine("Осем: " + eight);
  92.             Console.WriteLine("Девет: " + nine);
  93.         }
  94.  
  95.         //Функция за смяна на главните с малки букви
  96.         public static void ToLower(String input)
  97.         {
  98.             string output = input.ToLower();
  99.             Console.WriteLine(output);
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement