Advertisement
svetlyoek

Untitled

Feb 22nd, 2019
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp183
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> firstPlayer = Console.ReadLine().Split().Select(int.Parse).ToList();
  12. List<int> secondPlayer = Console.ReadLine().Split().Select(int.Parse).ToList();
  13. CompareCards(firstPlayer, secondPlayer);
  14.  
  15. }
  16.  
  17.  
  18. private static void CompareCards(List<int> firstPlayer, List<int> secondPlayer)
  19. {
  20. while (firstPlayer.Count > 0 || secondPlayer.Count > 0)
  21. {
  22. if(firstPlayer.Count==0||secondPlayer.Count==0)
  23. {
  24. break;
  25. }
  26.  
  27. for (int i = 0; i < firstPlayer.Count-1; i++)
  28. {
  29. for (int j = 0; j < secondPlayer.Count-1; j++)
  30. {
  31. if (firstPlayer[i] > secondPlayer[j])
  32. {
  33.  
  34. firstPlayer.Add(firstPlayer[i]);
  35. firstPlayer.RemoveAt(firstPlayer[i]);
  36. firstPlayer.Add(secondPlayer[j]);
  37. secondPlayer.RemoveAt(secondPlayer[j]);
  38. }
  39. else if (secondPlayer[j] > firstPlayer[i])
  40. {
  41. secondPlayer.Add(secondPlayer[j]);
  42. secondPlayer.RemoveAt(secondPlayer[j]);
  43. secondPlayer.Add(firstPlayer[i]);
  44. firstPlayer.RemoveAt(firstPlayer[i]);
  45. }
  46. else if (firstPlayer[i] == secondPlayer[j])
  47. {
  48.  
  49. firstPlayer.RemoveAt(firstPlayer[i]);
  50. firstPlayer.RemoveAt(secondPlayer[j]);
  51. secondPlayer.RemoveAt(firstPlayer[i]);
  52. secondPlayer.RemoveAt(secondPlayer[j]);
  53. }
  54.  
  55. }
  56. }
  57. }
  58. if (firstPlayer.Count > 0)
  59. {
  60. int sum = 0;
  61. sum = firstPlayer.Sum();
  62. Console.WriteLine($"First player wins! Sum: {sum}");
  63. }
  64. else if (secondPlayer.Count > 0)
  65. {
  66. int sum = 0;
  67. sum = secondPlayer.Sum();
  68. Console.WriteLine($"Second player wins! Sum: {sum}");
  69. }
  70.  
  71. }
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement