Guest User

Untitled

a guest
May 21st, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace _2chSolver
  6. {
  7.     class Program
  8.     {
  9.         //Eng 97 122
  10.         //Rus 1072 1103
  11.         private static readonly char[] Vowels = new [] { 'a', 'e', 'y', 'u', 'i', 'o', 'а', 'у', 'е', 'э', 'о', 'ы', 'я', 'и', 'ю' };
  12.  
  13.         private enum PreviousCharType
  14.         {
  15.             Consonant,
  16.             Vowel,
  17.             None
  18.         }
  19.  
  20.         static void Main(string[] args)
  21.         {
  22.             int rus = 0;
  23.             int eng = 0;
  24.             int vowels = 0;
  25.             int consonantsAfterVowels = 0;
  26.             int vowelsAfterConsonants = 0;
  27.             PreviousCharType prevCharType = PreviousCharType.None;
  28.            
  29.  
  30.             using (var reader = new StreamReader("input.txt"))
  31.             {
  32.                 do
  33.                 {
  34.                     var ch = Char.ToLower((char) reader.Read());
  35.                     var currentCharType = PreviousCharType.None;
  36.  
  37.                     if (ch <= 122 && ch >= 97)
  38.                     {
  39.                         eng++;
  40.                         currentCharType = PreviousCharType.Consonant;
  41.                     }
  42.  
  43.                     if (ch <= 1103 && ch >= 1072)
  44.                     {
  45.                         rus++;
  46.                         currentCharType = PreviousCharType.Consonant;
  47.                     }
  48.  
  49.                     if (Vowels.Contains(ch))
  50.                     {
  51.                         vowels++;
  52.                         currentCharType = PreviousCharType.Vowel;
  53.                     }
  54.  
  55.                     if (prevCharType == PreviousCharType.Consonant && currentCharType == PreviousCharType.Vowel)
  56.                     {
  57.                         vowelsAfterConsonants++;
  58.                     }
  59.  
  60.                     if (prevCharType == PreviousCharType.Vowel && currentCharType == PreviousCharType.Consonant)
  61.                     {
  62.                         consonantsAfterVowels++;
  63.                     }
  64.  
  65.                     prevCharType = currentCharType;
  66.                 }
  67.                 while (!reader.EndOfStream);
  68.  
  69.                 Console.WriteLine("Results");
  70.                 Console.WriteLine($"Rus: {rus}");
  71.                 Console.WriteLine($"Eng: {eng}");
  72.                 Console.WriteLine($"Vowels: {vowels * 1.0 / (rus + eng) * 100} %");
  73.                 Console.WriteLine($"Consonants: {(rus + eng - vowels) * 1.0 / (rus + eng) * 100} %");
  74.                 Console.WriteLine($"VowelsAfterConsonants: {vowelsAfterConsonants}");
  75.                 Console.WriteLine($"ConsonantsAfterVowels: {consonantsAfterVowels}");
  76.                 Console.ReadKey();
  77.  
  78.             }
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment