Advertisement
Guest User

Untitled

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