Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace _02.RobotCommunication
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var charToWord = new List<string>();
- while (true)
- {
- if (input == "Report")
- {
- break;
- }
- string pattern = @"(?:[\\_\\,])[A-Za-z]+[0-9]";
- var matches = Regex.Matches(input, pattern);
- charToWord = new List<string>();
- foreach (var mach in matches)
- {
- string result = mach.ToString();
- char num = result[result.Length - 1];
- int number = (int)Char.GetNumericValue(num);
- var collection = new List<int>();
- string toString = string.Empty;
- if (result[0] == ',')
- {
- for (int i = 1; i < result.Length - 1; i++)
- {
- collection.Add(result[i]);
- }
- for (int i = 0; i < collection.Count; i++)
- {
- collection[i] += number;
- }
- for (int i = 0; i < collection.Count; i++)
- {
- var chars = Convert.ToChar(collection[i]);
- toString += chars;
- }
- charToWord.Add(toString);
- }
- else if (result[0] == '_')
- {
- for (int i = 1; i < result.Length - 1; i++)
- {
- collection.Add(result[i]);
- }
- for (int i = 0; i < collection.Count; i++)
- {
- collection[i] -= number;
- }
- for (int i = 0; i < collection.Count; i++)
- {
- var chars = Convert.ToChar(collection[i]);
- toString += chars;
- }
- charToWord.Add(toString);
- }
- }
- if (charToWord.Count > 0)
- {
- Console.WriteLine(string.Join(" ", charToWord));
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement