Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Design;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.Linq;
  6.  
  7. namespace ConsoleApp6
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             List<int> firstPlayerDeck = Console.ReadLine()
  15.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  16.                 .Select(int.Parse)
  17.                 .ToList();
  18.  
  19.             List<int> secondPlayerDeck = Console.ReadLine()
  20.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  21.                 .Select(int.Parse)
  22.                 .ToList();
  23.  
  24.  
  25.             while (true)
  26.             {
  27.  
  28.                 if (firstPlayerDeck.FirstOrDefault() > secondPlayerDeck.FirstOrDefault())
  29.                 {
  30.  
  31.                     firstPlayerDeck.Add(firstPlayerDeck.FirstOrDefault());
  32.                     firstPlayerDeck.Remove(firstPlayerDeck.FirstOrDefault());
  33.                     firstPlayerDeck.Add(secondPlayerDeck.FirstOrDefault());
  34.                     secondPlayerDeck.Remove(secondPlayerDeck.FirstOrDefault());
  35.                 }
  36.  
  37.                 else if (secondPlayerDeck.FirstOrDefault() > firstPlayerDeck.FirstOrDefault())
  38.                 {
  39.                     secondPlayerDeck.Add(secondPlayerDeck.FirstOrDefault());
  40.                     secondPlayerDeck.Remove(secondPlayerDeck.FirstOrDefault());
  41.                     secondPlayerDeck.Add(firstPlayerDeck.FirstOrDefault());
  42.                     firstPlayerDeck.Remove(firstPlayerDeck.FirstOrDefault());
  43.                 }
  44.  
  45.                 else
  46.                 {
  47.                     firstPlayerDeck.Remove(firstPlayerDeck.FirstOrDefault());
  48.                     secondPlayerDeck.Remove(secondPlayerDeck.FirstOrDefault());
  49.  
  50.                 }
  51.  
  52.                 if (firstPlayerDeck.Count == 0)
  53.                 {
  54.                     Console.WriteLine($"Second player wins! Sum: {secondPlayerDeck.Sum()}");
  55.                     break;
  56.                 }
  57.                 else if (secondPlayerDeck.Count == 0)
  58.                 {
  59.                     Console.WriteLine($"First player wins! Sum: {firstPlayerDeck.Sum()}");
  60.                     break;
  61.                 }
  62.             }
  63.  
  64.         }
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement