Advertisement
knoteva

Untitled

Dec 27th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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.  
  19.             var key = Console.ReadLine()
  20.                 .Split(' ')
  21.                 .Select(int.Parse)
  22.                 .ToList();
  23.             int currPos = 0;
  24.             string sequence;
  25.             string regex = @"&(?<type>.+)&[^<]*<(?<coord>.+)>";
  26.  
  27.             while ((sequence = Console.ReadLine()) != "find")
  28.             {
  29.  
  30.                 int keyLength = key.Count;
  31.                 int sequenceLength = sequence.Length;
  32.                 var sb = new StringBuilder();
  33.  
  34.                 for (int i = keyLength; i < sequenceLength; i++)
  35.                 {
  36.                     key.Add(key[currPos]);
  37.                     currPos++;
  38.                 }
  39.  
  40.                 for (int i = 0; i < sequenceLength; i++)
  41.                 {
  42.                     sb.Append((char)(sequence[i] - key[i]));
  43.                 }
  44.  
  45.                 Match m = Regex.Match(sb.ToString(), regex);
  46.                 if (m.Success)
  47.                 {
  48.                     string type = m.Groups["type"].Value;
  49.                     string coord = m.Groups["coord"].Value;
  50.                     Console.WriteLine($"Found {type} at {coord}");
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement