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;
- using System.Threading.Tasks;
- namespace _4.CubicMessages
- {
- class CubicMessages
- {
- static void Main()
- {
- string code = Console.ReadLine();
- StringBuilder builder = new StringBuilder();
- while (!code.Equals("Over!"))
- {
- int decryptorSize = int.Parse(Console.ReadLine());
- Regex check = new Regex(@"^(\d+)([a-zA-Z]+)([^a-zA-Z]*)$");
- if (check.Match(code).Success && check.Match(code).Groups[2].Length == decryptorSize)
- {
- Match matches = check.Match(code);
- string val = matches.Groups[1].Value;
- for (int i = 0; i < val.Length; i++)
- {
- if (int.Parse(val[i] + "") >= 0 && int.Parse(val[i] + "") < decryptorSize)
- {
- builder.Append(matches.Groups[2].Value[int.Parse(val[i] + "")]);
- }
- else
- {
- builder.Append(" ");
- }
- }
- string val2 = matches.Groups[3].Value;
- int[] nums = getVal2(val2);
- for (int i = 0; i < val2.Length; i++)
- {
- if (nums[i] >= 0 && nums[i] < decryptorSize)
- {
- builder.Append(matches.Groups[2].Value[nums[i]].ToString());
- }
- else
- {
- builder.Append(" ");
- }
- }
- Console.WriteLine("{0} == {1}", matches.Groups[2].Value,builder.ToString());
- }
- code = Console.ReadLine();
- builder = new StringBuilder();
- }
- }
- private static int[] getVal2(string val2)
- {
- char[] a = val2.ToCharArray();
- int[] b = new int[a.Length];
- for (int i = 0; i < a.Length; i++)
- {
- if (char.IsDigit(a[i]))
- {
- b[i] = int.Parse(a[i] + "");
- }
- else
- {
- b[i] = -1;
- }
- }
- return b;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement