Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- namespace _2chSolver
- {
- class Program
- {
- //Eng 97 122
- //Rus 1072 1103
- private static readonly char[] Vowels = new [] { 'a', 'e', 'y', 'u', 'i', 'o', 'а', 'у', 'е', 'э', 'о', 'ы', 'я', 'и', 'ю' };
- private enum PreviousCharType
- {
- Consonant,
- Vowel,
- None
- }
- static void Main(string[] args)
- {
- int rus = 0;
- int eng = 0;
- int vowels = 0;
- int consonantsAfterVowels = 0;
- int vowelsAfterConsonants = 0;
- PreviousCharType prevCharType = PreviousCharType.None;
- var sw = new Stopwatch();
- sw.Start();
- using (var reader = new StreamReader("input.txt"))
- {
- var inputString = reader.ReadToEnd().ToLower();
- eng = inputString.ToCharArray().Count(ch => ch <= 122 && ch >= 97);
- rus = inputString.ToCharArray().Count(ch => ch <= 1103 && ch >= 1072);
- vowels = inputString.ToCharArray().Count(ch => Vowels.Contains(ch));
- var pairs = new List<string>();
- for (int i = 0; i < inputString.Length - 1; i++)
- {
- pairs.Add(inputString[i] + inputString[i + 1].ToString());
- }
- consonantsAfterVowels =
- pairs.Count(
- ch =>
- Vowels.Contains(ch[0]) && (ch[1] <= 122 && ch[1] >= 97 || ch[1] <= 1103 && ch[1] >= 1072) &&
- !Vowels.Contains(ch[1]));
- vowelsAfterConsonants =
- pairs.Count(
- ch =>
- Vowels.Contains(ch[1]) && (ch[0] <= 122 && ch[0] >= 97 || ch[0] <= 1103 && ch[0] >= 1072) &&
- !Vowels.Contains(ch[0]));
- Console.WriteLine("Results");
- Console.WriteLine($"Rus: {rus}");
- Console.WriteLine($"Eng: {eng}");
- Console.WriteLine($"Vowels: {vowels * 1.0 / (rus + eng) * 100} %");
- Console.WriteLine($"Consonants: {(rus + eng - vowels) * 1.0 / (rus + eng) * 100} %");
- Console.WriteLine($"VowelsAfterConsonants: {vowelsAfterConsonants}");
- Console.WriteLine($"ConsonantsAfterVowels: {consonantsAfterVowels}");
- }
- sw.Stop();
- Console.WriteLine($"{sw.Elapsed.TotalSeconds} s");
- Console.WriteLine();
- sw.Reset();
- sw.Start();
- using (var reader = new StreamReader("input.txt"))
- {
- rus = 0;
- eng = 0;
- vowels = 0;
- consonantsAfterVowels = 0;
- vowelsAfterConsonants = 0;
- do
- {
- var ch = Char.ToLower((char) reader.Read());
- var currentCharType = PreviousCharType.None;
- if (ch <= 122 && ch >= 97)
- {
- eng++;
- currentCharType = PreviousCharType.Consonant;
- }
- if (ch <= 1103 && ch >= 1072)
- {
- rus++;
- currentCharType = PreviousCharType.Consonant;
- }
- if (Vowels.Contains(ch))
- {
- vowels++;
- currentCharType = PreviousCharType.Vowel;
- }
- if (prevCharType == PreviousCharType.Consonant && currentCharType == PreviousCharType.Vowel)
- {
- vowelsAfterConsonants++;
- }
- if (prevCharType == PreviousCharType.Vowel && currentCharType == PreviousCharType.Consonant)
- {
- consonantsAfterVowels++;
- }
- prevCharType = currentCharType;
- } while (!reader.EndOfStream);
- Console.WriteLine("Results");
- Console.WriteLine($"Rus: {rus}");
- Console.WriteLine($"Eng: {eng}");
- Console.WriteLine($"Vowels: {vowels*1.0/(rus + eng)*100} %");
- Console.WriteLine($"Consonants: {(rus + eng - vowels)*1.0/(rus + eng)*100} %");
- Console.WriteLine($"VowelsAfterConsonants: {vowelsAfterConsonants}");
- Console.WriteLine($"ConsonantsAfterVowels: {consonantsAfterVowels}");
- }
- sw.Stop();
- Console.WriteLine($"{sw.Elapsed.TotalSeconds} s");
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement