Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace _02.RobotCommunication
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- string line = Console.ReadLine();
- string pattern = @"[,|_]{1}([\d|\w]+)";
- List<string> data = new List<string>();
- Regex regex = new Regex(pattern);
- FindData(line, data);
- NewMethod(data, regex);
- while (true)
- {
- line = Console.ReadLine();
- if (line == "Report")
- {
- break;
- }
- data.Clear();
- FindData(line, data);
- NewMethod(data, regex);
- }
- }
- private static void NewMethod(List<string> data, Regex regex)
- {
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < data.Count; i++)
- {
- stringBuilder.AppendLine(data[i]);
- }
- string something = stringBuilder.ToString();
- var matchColection = regex.Matches(something);
- for (int i = 0; i < matchColection.Count; i++)
- {
- string decoded = string.Empty;
- int sum = 0;
- string stoinost = matchColection[i].Value;
- char digid = stoinost[0];
- for (int j = 0; j < stoinost.Length; j++)
- {
- int num;
- bool isNum = int.TryParse(stoinost[j].ToString(), out num);
- if (isNum)
- {
- if (digid == ',')
- {
- sum += num;
- }
- else if(digid=='_')
- {
- sum -= num;
- }
- }
- }
- for (int j = 1; j < stoinost.Length; j++)
- {
- int num;
- bool isNum = int.TryParse(stoinost[j].ToString(), out num);
- if (!isNum)
- {
- int code = stoinost[j];
- code += sum;
- char s = Convert.ToChar(code);
- decoded += s;
- }
- else
- {
- break;
- }
- }
- Console.Write(decoded + " ");
- }
- Console.WriteLine();
- }
- private static void FindData(string line, List<string> data)
- {
- for (int i = 0; i < line.Length; i++)
- {
- if (line[i] == '_' || line[i] == ',')
- {
- int startIndex = i;
- int startLine = startIndex + 1;
- while (true)
- {
- if (line[startLine] == '_' || line[startLine] == ',' || startLine + 1 == line.Length)
- {
- if (startLine + 1 == line.Length)
- {
- data.Add(line.Substring(startIndex));
- }
- else
- {
- data.Add(line.Substring(startIndex, startLine - startIndex));
- }
- break;
- }
- startLine++;
- if (startLine == line.Length)
- {
- break;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement