Advertisement
Guest User

Untitled

a guest
Apr 14th, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace WinnerTicket
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             string[] inputString = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  13.  
  14.  
  15.  
  16.             for (int i = 0; i < inputString.Length; i++)
  17.             {
  18.                 if (inputString[i].Length == 20)
  19.                 {
  20.                     InputPattern(inputString[i]);
  21.  
  22.                 }
  23.                 else
  24.                 {
  25.                     Console.WriteLine($"invalid ticket");
  26.                 }
  27.  
  28.             }
  29.         }
  30.  
  31.          static void InputPattern(string v)
  32.         {
  33.            
  34.             string input = v;
  35.             string pattern = @"([@]{6,10}|[#]{6,10}|[$]{6,10}|[\^]{6,10})[A-Za-z0-9]*([@]{6,10}|[#]{6,10}|[$]{6,10}|[\^]{6,10})";
  36.  
  37.            
  38.                 Match match = Regex.Match(input, pattern);
  39.  
  40.                 string b = match.Groups[1].ToString();
  41.                 string a = match.Groups[2].ToString();
  42.  
  43.  
  44.                 if (b.Length >= 6 && b.Length <= 10)
  45.                 {
  46.                     if (b.Length == 10 && a.Length == 10)
  47.                     {
  48.                         string symbol = b.Substring(1, 1);
  49.                         string symbol1 = a.Substring(1, 1);
  50.                         if (symbol == symbol1)
  51.                         {
  52.                             Console.WriteLine($"ticket \"{input}\" - {b.Length}{symbol} Jackpot!");
  53.                             return;
  54.                         }
  55.                     }
  56.                     else
  57.                     {
  58.  
  59.                         string symbol = b.Substring(1, 1);
  60.                         string symbol1 = a.Substring(1, 1);
  61.  
  62.                         if (symbol == symbol1)
  63.                         {
  64.                             int len = Math.Min(a.Length, b.Length);
  65.  
  66.                             Console.WriteLine($"ticket \"{input}\" - {len}{symbol}");
  67.                             return;
  68.                         }
  69.                     }
  70.  
  71.                 }else
  72.             {
  73.  
  74.                 Console.WriteLine($"ticket \"{input}\" - no match");
  75.             }
  76.  
  77.  
  78.  
  79.         }
  80.  
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement