Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp183
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> firstPlayer = Console.ReadLine().Split().Select(int.Parse).ToList();
- List<int> secondPlayer = Console.ReadLine().Split().Select(int.Parse).ToList();
- CompareCards(firstPlayer, secondPlayer);
- }
- private static void CompareCards(List<int> firstPlayer, List<int> secondPlayer)
- {
- while (firstPlayer.Count > 0 || secondPlayer.Count > 0)
- {
- if(firstPlayer.Count==0||secondPlayer.Count==0)
- {
- break;
- }
- for (int i = 0; i < firstPlayer.Count-1; i++)
- {
- for (int j = 0; j < secondPlayer.Count-1; j++)
- {
- if (firstPlayer[i] > secondPlayer[j])
- {
- firstPlayer.Add(firstPlayer[i]);
- firstPlayer.RemoveAt(firstPlayer[i]);
- firstPlayer.Add(secondPlayer[j]);
- secondPlayer.RemoveAt(secondPlayer[j]);
- }
- else if (secondPlayer[j] > firstPlayer[i])
- {
- secondPlayer.Add(secondPlayer[j]);
- secondPlayer.RemoveAt(secondPlayer[j]);
- secondPlayer.Add(firstPlayer[i]);
- firstPlayer.RemoveAt(firstPlayer[i]);
- }
- else if (firstPlayer[i] == secondPlayer[j])
- {
- firstPlayer.RemoveAt(firstPlayer[i]);
- firstPlayer.RemoveAt(secondPlayer[j]);
- secondPlayer.RemoveAt(firstPlayer[i]);
- secondPlayer.RemoveAt(secondPlayer[j]);
- }
- }
- }
- }
- if (firstPlayer.Count > 0)
- {
- int sum = 0;
- sum = firstPlayer.Sum();
- Console.WriteLine($"First player wins! Sum: {sum}");
- }
- else if (secondPlayer.Count > 0)
- {
- int sum = 0;
- sum = secondPlayer.Sum();
- Console.WriteLine($"Second player wins! Sum: {sum}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement