EmoRz

WinningTicket

Jun 17th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace WinningTickets
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] input = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  11.  
  12.             foreach (var tick in input)
  13.             {
  14.  
  15.                 var left = new string(tick.Take(10).ToArray());
  16.                 var right = new string(tick.Skip(10).Take(10).ToArray());
  17.  
  18.                 var countL = SeqCount(left);
  19.                 var countR = SeqCount(right);
  20.                 var min = Math.Min(countL, countR);
  21.                 if (tick.Length != 20)
  22.                 {
  23.                     Console.WriteLine("invalid ticket");
  24.                 }
  25.                 else
  26.                 {
  27.                     var symbol = "";
  28.                     foreach (var item in tick)
  29.                     {
  30.                         if (item == '@' || item == '#' || item == '$' || item == '^')
  31.                         {
  32.                             symbol = item.ToString();
  33.                             break;
  34.                         }
  35.                     }
  36.                     if (min == 10)
  37.                     {
  38.                         Console.Write($"ticket ");
  39.                         Console.Write($"\"{tick}\"");
  40.                         Console.WriteLine($" - {min}{symbol} Jackpot!");
  41.                     }
  42.                     else if (min >= 6 && min <10)
  43.                     {
  44.                         Console.Write($"ticket ");
  45.                         Console.Write($"\"{tick}\"");
  46.                         Console.WriteLine($" - {min}{symbol}");
  47.                     }
  48.                     else
  49.                     {
  50.                         Console.Write($"ticket ");
  51.                         Console.Write($"\"{tick}\" - ");
  52.                         Console.WriteLine("no match");
  53.                     }
  54.                 }
  55.  
  56.  
  57.  
  58.             }
  59.  
  60.         }
  61.         static int SeqCount(string side)
  62.         {
  63.             int count = 1;
  64.             int longest = int.MinValue;
  65.             //
  66.             for (int i = 0; i < side.Length - 1; i++)
  67.             {
  68.                 var cuurent = side[i];
  69.                 var next = side[i + 1];
  70.  
  71.                 if ('@' == side[i] || '#' == side[i] || '$' == side[i] || '^' == side[i])
  72.                 {
  73.                     if (cuurent == next)
  74.                     {
  75.                         count++;
  76.                     }
  77.                 }
  78.                 else
  79.                 {
  80.                     longest = count;
  81.                     count = 1;
  82.                 }
  83.             }
  84.             if (count > longest)
  85.             {
  86.                 longest = count;
  87.                 count = 1;
  88.             }
  89.  
  90.             return longest;
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment