Advertisement
Danny_Berova

CryptoBlockchain

Feb 11th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _03.Problem
  6. {
  7.     public class ProblemThree
  8.     {
  9.         public static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             var sticked = new StringBuilder();
  13.             var output = new StringBuilder();
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 sticked.Append(Console.ReadLine());
  18.             }
  19.  
  20.             var pattern = @"\[([^\d\[\]\{\}]*)(?<numbers>[\d]{3,})([^\[\]\{\}]*)\]|\{([^\d\[\]\{\}]*)(?<numbers>[\d]{3,})([^\[\]\{\}]*)\}";
  21.             Regex regex = new Regex(pattern);
  22.  
  23.             MatchCollection cryptoBlocks = regex.Matches(sticked.ToString());
  24.  
  25.             for (int i = 0; i < cryptoBlocks.Count; i++)
  26.             {
  27.                 if (cryptoBlocks[i].Groups["numbers"].Value.Length % 3 != 0)
  28.                 {
  29.                     continue;
  30.                 }
  31.  
  32.                 var currentBlock = cryptoBlocks[i].Groups["numbers"].Value;
  33.                 var numbersLength = cryptoBlocks[i].Groups["numbers"].Value.Length;
  34.                 var totalLength = cryptoBlocks[i].Length;
  35.  
  36.                 while (currentBlock.Length > 0)
  37.                 {
  38.                     var currentChar = currentBlock.Substring(0, 3);
  39.                     output.Append((char)(int.Parse(currentChar) - totalLength));
  40.                     currentBlock = currentBlock.Substring(3);
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine(output);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement