main (1).cs 3.97 KiB
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
using System;
using System.Linq;
class HelloWorld {
  static bool char_in_string(char ch, string str)
      foreach(char ch_ in str)
          if(ch_ == ch) return true;
      return false;
  static bool string_in_array_of_strings(string str1, string[] arr_of_strings)
      foreach(string str in arr_of_strings)
          if(str == str1) return true;
      return false;
  static void Main() {
      Console.Write("Input: ");
      string input_string = Console.ReadLine();
      string[] possible_prefixies = {"взо", "изо", "надо", "недо", "пред", "предо", "подо", "ото", "обо", "разо", "роз", "раз", "рос", "рас", "через" , "черес", "под"}; // Specific prefixies for proper implementation. 
      string prefix = ""; 
      char[] russian_vowels = {'у', 'е', 'ы', 'а', 'о', 'э', 'я', 'и', 'ю',
                               'У', 'Е', 'Ы', 'А', 'О', 'Э', 'Я', 'И', 'Ю'
      char[] russian_consonants = {'й', 'ц', 'к', 'н', 'г','ш', 'щ', 'з', 'х', 'ъ', 'в', 'п', 'р', 'л', 'д','ж', 'ч', 'с', 'м', 'т', 'ь', 'б',
                                   'Й', 'Ц', 'К', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х', 'Ъ', 'В', 'П', 'Р', 'Л', 'Д', 'Ж', 'Ч', 'С', 'М', 'T', 'Ь', 'Б'
      string string_of_vowels = new string(russian_vowels);
      string string_of_consonants = new string(russian_consonants);
      string specific_consonants = "ьъйЙЬЪ";
       int i = 5;
      if(input_string.Length > 5)
      for(; i > 0; i--)
        if(string_in_array_of_strings(input_string.Substring(0, i),possible_prefixies))
            prefix = input_string.Substring(0, i);
            break;
      else
          i = 0;
      bool encountered_consonant = false;
      bool encountered_vowel = false;
      int prev_ind = 0;
      bool dont_need_dash = true;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
if(prefix.Length > 0){ Console.Write(prefix); dont_need_dash = false; prev_ind = prefix.Length; } for(; i < input_string.Length; i++) { if(char_in_string(input_string[i], string_of_consonants)) { encountered_consonant = true; } else if(char_in_string(input_string[i], string_of_vowels)) { encountered_vowel = true; } else{ throw new ArgumentException("Input string suppose to have only russian characters. Please take it into account and try again."); } if(encountered_consonant && encountered_vowel) { if(char_in_string(input_string[i], string_of_vowels) || ((input_string.Length > i + 1) && char_in_string(input_string[i + 1], string_of_consonants)) || char_in_string(input_string[i], specific_consonants)) { if(dont_need_dash) { Console.Write(input_string.Substring(prev_ind, i - prev_ind + 1)); dont_need_dash = false; } else { Console.Write("-" + input_string.Substring(prev_ind, i - prev_ind + 1)); } prev_ind = i + 1; } encountered_vowel = false; encountered_consonant = false; } } Console.Write(input_string.Substring(prev_ind, input_string.Length - prev_ind)); } }