petyaminkova91

Untitled

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