Advertisement
Spocoman

06. Cards Game

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