Advertisement
knoteva

Untitled

Dec 27th, 2019
1,222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Numerics;
  6. using System.Threading.Tasks;
  7. using System.Collections;
  8. using System.Globalization;
  9. using System.Text.RegularExpressions;
  10.  
  11.  
  12. namespace ConsoleApp
  13. {
  14.     class Program
  15.     {
  16.         static void Main()
  17.         {
  18.             var key = Console.ReadLine()
  19.                 .Split(' ')
  20.                 .Select(int.Parse)
  21.                 .ToList();
  22.             int currPos = 0;
  23.             string sequence;
  24.             string regex = @"&(?<type>.+)&[^<]*<(?<coord>.+)>";
  25.  
  26.             while ((sequence = Console.ReadLine()) != "find")
  27.             {
  28.                 int keyLength = key.Count;
  29.                 int sequenceLength = sequence.Length;
  30.                 var sb = new StringBuilder();
  31.  
  32.                 for (int i = keyLength; i < sequenceLength; i++)
  33.                 {
  34.                     key.Add(key[currPos]);
  35.                     currPos++;
  36.                 }
  37.  
  38.                 for (int i = 0; i < sequenceLength; i++)
  39.                 {
  40.                     sb.Append((char)(sequence[i] - key[i]));
  41.                 }
  42.  
  43.                 Match m = Regex.Match(sb.ToString(), regex);
  44.  
  45.                 if (m.Success)
  46.                 {
  47.                     string type = m.Groups["type"].Value;
  48.                     string coord = m.Groups["coord"].Value;
  49.                     Console.WriteLine($"Found {type} at {coord}");
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement