Advertisement
radostina92

Untitled

Nov 4th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace cardGames2222
  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 (firstPlayer.Count != 0)
  21.             {
  22.                 if (secondPlayer.Count == 0)
  23.                 {
  24.                     break;
  25.                 }
  26.  
  27.                 int firstPlayerCard = firstPlayer[0];
  28.                 int secondPlayerCard = secondPlayer[0];
  29.  
  30.                 if (firstPlayerCard > secondPlayerCard)
  31.                 {
  32.                     firstPlayer.Add(firstPlayerCard);
  33.                     firstPlayer.Add(secondPlayerCard);
  34.  
  35.                     firstPlayer.RemoveAt(0);
  36.                     secondPlayer.RemoveAt(0);
  37.                 }
  38.                 else if (firstPlayerCard < secondPlayerCard)
  39.                 {
  40.                     secondPlayer.Add(secondPlayerCard);
  41.                     secondPlayer.Add(firstPlayerCard);
  42.  
  43.  
  44.                     firstPlayer.RemoveAt(0);
  45.                     secondPlayer.RemoveAt(0);
  46.                 }
  47.                 else
  48.                 {
  49.                     firstPlayer.RemoveAt(0);
  50.                     secondPlayer.RemoveAt(0);
  51.                 }
  52.                
  53.             }
  54.  
  55.             if (firstPlayer.Count == 0)
  56.             {
  57.                 Console.WriteLine($"Second player wins! Sum: {secondPlayer.Sum()}");
  58.             }
  59.             else
  60.             {
  61.                 Console.WriteLine($"First player wins! Sum: {firstPlayer.Sum()}");
  62.             }
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement