Advertisement
gospod1978

Exam\The Isle of Man TT Race 02

Oct 16th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Text.RegularExpressions;
  8.  
  9.  
  10. namespace Orders
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.        
  17.        
  18.         while(true)
  19.         {
  20.             string input = Console.ReadLine();
  21.                
  22. string pattern = @"([#$%*&])(\w+)\1=(\d+)!!(.*)$";
  23.    
  24.    Match match = Regex.Match(input, pattern);
  25.    
  26.    if (match.Success)
  27.    {
  28.    
  29.        string name = match.Groups[2].Value;
  30.        int length = int.Parse(match.Groups[3].Value);
  31.        string coord = match.Groups[4].Value;
  32.        
  33.        if (length == coord.Length)
  34.        {
  35.        StringBuilder sb = new StringBuilder();
  36.        
  37.        for (int i = 0; i < coord.Length; i++)
  38.        {
  39.         sb.Append((char)(coord[i] + coord.Length));
  40.        }
  41.        
  42.        Console.WriteLine($"Coordinates found! {name} -> {sb}");
  43.        break;
  44.    }
  45.    //Console.WriteLine(length);        
  46.             }
  47.             Console.WriteLine("Nothing found!");
  48.         }  
  49.            
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement