Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace WinningTicket
  7. {
  8.     class WinningTicket
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> input = Console.ReadLine().Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  13.             string pattern = @"(\^{6,10}|\#{6,10}|\${6,10}|\@{6,10})(\w*|\W*)(\1)";
  14.             for (int i = 0; i < input.Count; i++)
  15.             {
  16.                 if (input[i].Length != 20)
  17.                 {
  18.                     Console.WriteLine("invalid ticket");
  19.                 }
  20.                 else if (Regex.IsMatch(input[i],pattern)==false)
  21.                 {
  22.                     Console.WriteLine($"ticket \"{input[i]}\" - no match");
  23.                 }
  24.                 else
  25.                 {
  26.                     var match = Regex.Match(input[i], pattern);
  27.                    
  28.                     string temp = match.Groups[1].Value;
  29.                     if (temp.Length == 10)
  30.                     {
  31.                         Console.WriteLine($"ticket \"{input[i]}\" - 10{temp[0]} Jackpot!");
  32.                     }
  33.                     else
  34.                     {
  35.                         int count = 0;
  36.                         for (int j = 0; j < temp.Length; j++)
  37.                         {
  38.                             count++;
  39.                         }
  40.                         Console.WriteLine($"ticket \"{input[i]}\" - {count}{temp[0]}");
  41.                     }
  42.                    
  43.                 }
  44.  
  45.             }
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement