Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace mainSolution
- {
- class Input
- {
- private static IEnumerator<string> getin()
- {
- while (true)
- foreach (string s in Console.ReadLine().Split().Where(x => x.Length > 0))
- yield return s;
- }
- private IEnumerator<string> inp = getin();
- public string GetString() { inp.MoveNext(); return inp.Current; }
- public int GetInt() { return int.Parse(GetString()); }
- public long GetLong() { return long.Parse(GetString()); }
- public double GetDouble() { return double.Parse(GetString()); }
- }
- static class Program
- {
- const int MOD = 'я' - 'а' + 1;
- static string Generator(string s, int shift)
- {
- shift %= MOD;
- StringBuilder res = new StringBuilder();
- for (int i = 0; i < s.Length; i++)
- {
- if (char.IsLetter(s[i]))
- {
- char nxt = (char)(char.ToLower(s[i]) + shift);
- if (nxt > 'я')
- nxt -= (char)(MOD);
- res.Append(nxt);
- }
- else
- res.Append(s[i]);
- }
- return res.ToString();
- }
- public class Pair<T, K>
- {
- public T First { get; set; }
- public K Second { get; set; }
- }
- static List<Pair<int, int>> countOfChar(string s)
- {
- List< Pair<int, int> > res = new List< Pair<int, int> >(100);
- for (int i = 0; i < 100; i++)
- {
- res.Add(new Pair<int,int> ());
- res[i].Second = i;
- }
- for (int i = 0; i < s.Length; i++)
- {
- char cur = s[i];
- if (char.IsPunctuation(cur) || char.IsWhiteSpace(cur))
- continue;
- else
- res[cur - 'а'].First++;
- }
- res.Sort((x, y) => y.First.CompareTo(x.First));
- return res;
- }
- static StringBuilder NextPermutation (string s, int letter)
- {
- int shift = letter - 'о' + 'а';
- StringBuilder res = new StringBuilder();
- for (int i = 0; i < s.Length; i++)
- {
- char cur = s[i];
- if (char.IsPunctuation(cur) || char.IsWhiteSpace(cur))
- {
- res.Append(cur);
- continue;
- }
- cur -= (char)shift;
- if (cur < 'а')
- cur += (char)MOD;
- res.Append(cur);
- }
- return res;
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Введите исходный текст:\n");
- Input cin = new Input();
- string s = Console.ReadLine();
- Console.Write("\nВведите свиг: ");
- int shift = cin.GetInt();
- s = Generator(s, shift);
- Console.WriteLine($"\nСдвинутая на {shift} строка:\n");
- Console.WriteLine(s);
- List<Pair<int, int>> count;
- count = countOfChar(s);
- //for (int i = 0; i < count.Count; i++)
- //{
- // Console.WriteLine($"{i+1} {count[i].First} --- {count[i].Second}");
- //}
- Console.WriteLine("\nВозможный ответ:\n");
- StringBuilder answer = new StringBuilder();
- int it = 0;
- while (true)
- {
- answer = NextPermutation(s, count[it++].Second);
- Console.WriteLine(answer);
- Console.WriteLine("\nif answer is correct, press \"Enter\"\n");
- ConsoleKeyInfo cki = Console.ReadKey();
- if (cki.Key == ConsoleKey.Enter)
- break;
- Console.WriteLine("\n\nВозможный ответ:\n");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment