Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _06.CardsGame
  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. while (firstPlayer.Count != 0 && secondPlayer.Count != 0)
  14. {
  15. if (firstPlayer[0] == secondPlayer[0])
  16. {
  17. firstPlayer.RemoveAt(0);
  18. secondPlayer.RemoveAt(0);
  19. }
  20. else if (firstPlayer[0] > secondPlayer[0])
  21. { firstPlayer.Add(firstPlayer[0]);
  22. firstPlayer.Add(secondPlayer[0]);
  23. firstPlayer.RemoveAt(0);
  24. secondPlayer.RemoveAt(0);
  25. }
  26. else if (secondPlayer[0] > firstPlayer[0])
  27. {
  28. secondPlayer.Add(secondPlayer[0])
  29. secondPlayer.Add(firstPlayer[0]);
  30. secondPlayer.RemoveAt(0);
  31. firstPlayer.RemoveAt(0);
  32. }
  33. }
  34.  
  35. if (firstPlayer.Count > 0)
  36. {
  37. Console.WriteLine($"First player wins! Sum: {firstPlayer.Sum()}");
  38. }
  39. else if (secondPlayer.Count > 0)
  40. {
  41. Console.WriteLine($"Second player wins! Sum: {secondPlayer.Sum()}");
  42. }
  43. }
  44.  
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement