Advertisement
bullit3189

Winning Ticket - String And Text Proccessing

Feb 17th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _06WinningTicket
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string[] tickets = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11.  
  12. foreach (var ticket in tickets)
  13. {
  14. if (ticket.Length!=20)
  15. {
  16. Console.WriteLine("invalid ticket");
  17. continue;
  18. }
  19.  
  20. string leftHalf = ticket.Substring(0, 10);
  21. string rightHalf = ticket.Substring(10);
  22.  
  23. int length = 0;
  24. char bestSymbol = ' ';
  25.  
  26. for (int i = 6; i <=10; i++)
  27. {
  28. if (leftHalf.Contains(new string('@',i)) && rightHalf.Contains(new string('@',i)))
  29. {
  30. length = i;
  31. bestSymbol = '@';
  32. }
  33. else if (leftHalf.Contains(new string('$', i)) && rightHalf.Contains(new string('$', i)))
  34. {
  35. length = i;
  36. bestSymbol = '$';
  37. }
  38. else if (leftHalf.Contains(new string('#', i)) && rightHalf.Contains(new string('#', i)))
  39. {
  40. length = i;
  41. bestSymbol = '#';
  42. }
  43. else if (leftHalf.Contains(new string('^', i)) && rightHalf.Contains(new string('^', i)))
  44. {
  45. length = i;
  46. bestSymbol = '^';
  47. }
  48. }
  49.  
  50. if (length==0)
  51. {
  52. Console.WriteLine($"ticket \"{ticket}\" - no match");
  53. }
  54. else if (length ==10)
  55. {
  56. Console.WriteLine($"ticket \"{ticket}\" - {length}{bestSymbol} Jackpot!");
  57. }
  58. else
  59. {
  60. Console.WriteLine($"ticket \"{ticket}\" - {length}{bestSymbol}");
  61. }
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement