Advertisement
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;
- using System.Text.RegularExpressions;
- namespace SpyGram
- {
- class Program
- {
- static void Main(string[] args)
- {
- string privateKey = Console.ReadLine();
- int counter = 0;
- Dictionary<string, StringBuilder> answer = new Dictionary<string, StringBuilder>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "END")
- {
- break;
- }
- //recipient - Group1 message- Group2
- string pattern = @"^(?:TO)\:\s([A-Z]+)\;\s(?:MESSAGE)\:\s(.*)\;$";
- Regex regex = new Regex(pattern);
- Match match = regex.Match(input);
- List<char> changedChars = new List<char>();
- if (!match.Success)
- {
- continue;
- }
- if (!answer.ContainsKey(match.Groups[1].ToString()))
- {
- answer.Add(match.Groups[1].ToString(), new StringBuilder());
- }
- counter = 0;
- string toStringMatch = match.ToString();
- for (int i = 0; i < toStringMatch.Length; i++)
- {
- try
- {
- changedChars.Add(Convert.ToChar(toStringMatch[i] + int.Parse(privateKey[counter].ToString())));
- counter++;
- }
- catch (Exception)
- {
- counter = 0;
- i--;
- }
- }
- StringBuilder AppendingNewStr = new StringBuilder();
- foreach (var item in changedChars)
- {
- AppendingNewStr.Append(item);
- }
- answer[match.Groups[1].ToString()]=AppendingNewStr;
- }
- foreach (var item in answer.OrderBy(x=>x.Key))
- {
- Console.WriteLine(item.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement