Advertisement
LardaX

Cubic-Messages-Wrong-Again-and-Again

Oct 21st, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Cubic_Messages
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string pattern = @"(^\d+)([a-zA-Z]+)([^a-zA-Z]+?)$";
  15.             Regex regex = new Regex(pattern);
  16.  
  17.             string input = Console.ReadLine();
  18.  
  19.             while (!input.Equals("Over!"))
  20.             {
  21.                 int charLength = int.Parse(Console.ReadLine());
  22.                 Match match = regex.Match(input);
  23.                 StringBuilder sb = new StringBuilder();
  24.                 string firstGroup = match.Groups[1].ToString();
  25.                 string secondGroup = match.Groups[2].ToString();
  26.                 string thirdGroup = match.Groups[3].ToString();
  27.  
  28.                 if (secondGroup.Length.Equals(charLength))
  29.                 {
  30.  
  31.                     for (int i = 0; i < match.Groups[1].Length; i++)
  32.                     {
  33.  
  34.                         int index = int.Parse(firstGroup[i].ToString());
  35.                         if (index < secondGroup.Length)
  36.                         {
  37.                             sb.Append(secondGroup[index]);
  38.                         }
  39.                         else
  40.                         {
  41.                             sb.Append(" ");
  42.                         }
  43.                     }
  44.  
  45.  
  46.                     for (int i = 0; i < thirdGroup.Length; i++)
  47.                     {
  48.                         try
  49.                         {
  50.                             int index = int.Parse(thirdGroup[i].ToString());
  51.                             if (index < secondGroup.Length)
  52.                             {
  53.                                 sb.Append(secondGroup[index]);
  54.                             }
  55.                             else
  56.                             {
  57.                                 sb.Append(" ");
  58.                             }
  59.                         }
  60.                         catch (Exception)
  61.                         {
  62.  
  63.                         }
  64.                     }
  65.  
  66.  
  67.                     Console.WriteLine($"{match.Groups[2]} == {sb}");
  68.                 }
  69.  
  70.                 input = Console.ReadLine();
  71.             }
  72.  
  73.  
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement