Advertisement
Guest User

Untitled

a guest
Aug 31st, 2020
2,601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Data;
  7. using System.Collections.Immutable;
  8. using System.Security.Cryptography.X509Certificates;
  9.  
  10. namespace _000_boza
  11. {
  12.  
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. List<string> input = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList();
  18.  
  19. string command = Console.ReadLine();
  20.  
  21. int numberOfMoves = 0;
  22.  
  23. while (true)
  24. {
  25. if (command == "end")
  26. {
  27. break;
  28. }
  29.  
  30. numberOfMoves++;
  31.  
  32. string[] indexes = command.Split();
  33. int index1 = int.Parse(indexes[0]);
  34. int index2 = int.Parse(indexes[1]);
  35.  
  36.  
  37.  
  38. if (index1 >= 0 && index2 >= 0 && index1 < input.Count && index2 < input.Count && index1 != index2)
  39. {
  40. if (input[index1] == input[index2])
  41. {
  42. Console.WriteLine($"Congrats! You have found matching elements - {input[index1]}!");
  43.  
  44. if (index1 > index2)
  45. {
  46. input.RemoveAt(index1);
  47. input.RemoveAt(index2);
  48. }
  49. else
  50. {
  51. input.RemoveAt(index2);
  52. input.RemoveAt(index1);
  53. }
  54.  
  55. if (input.Count == 0)
  56. {
  57. Console.WriteLine($"You have won in {numberOfMoves} turns!");
  58. return;
  59. }
  60. }
  61. else if (input[index1] != input[index2])
  62. {
  63. Console.WriteLine("Try again!");
  64. }
  65. }
  66. else
  67. {
  68. input.Insert(input.Count / 2, $"-{numberOfMoves}a");
  69. input.Insert(input.Count / 2, $"-{numberOfMoves}a");
  70. Console.WriteLine("Invalid input! Adding additional elements to the board");
  71. }
  72.  
  73.  
  74.  
  75. //Console.WriteLine(String.Join(" ", input));
  76. command = Console.ReadLine();
  77. }
  78.  
  79. Console.WriteLine("Sorry you lose :(");
  80. Console.WriteLine(String.Join(" ", input));
  81.  
  82. }
  83.  
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement