bullit3189

Cards Game -Lists

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