Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
2,755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P06_CardsGame
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> firstPlayer = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15. List<int> secondPlayer = Console.ReadLine()
  16. .Split()
  17. .Select(int.Parse)
  18. .ToList();
  19.  
  20. while (true)
  21. {
  22. if (firstPlayer[0] > secondPlayer[0])
  23. {
  24. firstPlayer.Add(firstPlayer[0]);
  25. firstPlayer.Add(secondPlayer[0]);
  26. }
  27. else if (firstPlayer[0] < secondPlayer[0])
  28. {
  29. secondPlayer.Add(secondPlayer[0]);
  30. secondPlayer.Add(firstPlayer[0]);
  31. }
  32.  
  33. firstPlayer.Remove(firstPlayer[0]);
  34. secondPlayer.Remove(secondPlayer[0]);
  35.  
  36. if (firstPlayer.Count == 0)
  37. {
  38. int sum = secondPlayer.Sum();
  39. Console.WriteLine($"Second player wins! Sum: {sum}");
  40. break;
  41. }
  42. else if (secondPlayer.Count == 0)
  43. {
  44. int sum = firstPlayer.Sum();
  45. Console.WriteLine($"First player wins! Sum: {sum}");
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement