Advertisement
marangoni

Untitled

Dec 28th, 2019
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. namespace _03_Treasure_Finder
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             int[] key = Console.ReadLine()
  16.                 .Split()
  17.                 .Select(int.Parse)
  18.                 .ToArray();
  19.  
  20.             string input = Console.ReadLine();
  21.  
  22.             while (input != "find")
  23.             {
  24.                 List<char> charInput = input.ToList();
  25.                 int keyL = 0;
  26.                 for (int i = 0; i < charInput.Count; i++)
  27.                 {
  28.                     charInput[i] = Convert.ToChar(charInput[i] - key[keyL]);
  29.                     keyL ++;
  30.                     if (keyL == key.Length)
  31.                     {
  32.                         keyL = 0;
  33.                     }
  34.  
  35.                 }
  36.                 string pattern = @".*([&])(?'tr'[a-zA-Z]*)([&]).*([<])(?'coo'.*)([>])";
  37.                 char[] str = charInput.ToArray();
  38.                 string nnew = new string(str);
  39.                 Regex reg = new Regex(pattern);
  40.                 Match mat = reg.Match(nnew);
  41.                 if (mat.Success)
  42.                 {
  43.                     Console.WriteLine($"Found {mat.Groups["tr"]} at {mat.Groups["coo"]}");
  44.                 }
  45.                 input = Console.ReadLine();
  46.             }
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement