Advertisement
Guest User

Winning Ticket

a guest
Feb 18th, 2017
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _04.Winning_Ticket
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. List<string> input = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  15.  
  16. foreach (var ticket in input)
  17. {
  18. if (ticket.Count() != 20)
  19. {
  20. Console.WriteLine("invalid ticket");
  21. }
  22.  
  23. else
  24. {
  25. int count = ticket.Count();
  26. var leftPart = ticket.Substring(0, count / 2);
  27. var rightPart = ticket.Substring(count / 2);
  28.  
  29. Regex pattern = new Regex(@"[\@\#\$\^]+");
  30. Match leftMatch = pattern.Match(leftPart);
  31. Match rightMatch = pattern.Match(rightPart);
  32. int min = Math.Min(leftMatch.Length, rightMatch.Length);
  33.  
  34.  
  35. if (leftMatch.ToString().Substring(0,min) == rightMatch.ToString().Substring(0,min))
  36. {
  37. if (leftMatch.Length == 10)
  38. {
  39. Console.WriteLine($"ticket \"{ticket}\" - {min}{leftMatch.ToString().Substring(1, 1)} Jackpot!");
  40. }
  41.  
  42. else if (leftMatch.Length >= 6 && leftMatch.Length < 10)
  43. {
  44. Console.WriteLine($"ticket \"{ticket}\" - {min}{leftMatch.ToString().Substring(1, 1)}");
  45. }
  46. else
  47. {
  48. Console.WriteLine($"ticket \"{ticket}\" - no match");
  49. }
  50. }
  51.  
  52. else
  53. {
  54. Console.WriteLine($"ticket \"{ticket}\" - no match");
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement