Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace _03.NumberWars
- {
- public class NumberWars
- {
- public static void Main()
- {
- var firstQueue = new Queue<string>(Console.ReadLine().Split());
- var secondQueue = new Queue<string>(Console.ReadLine().Split());
- var turns = 0;
- var list = new List<string>();
- while (firstQueue.Count > 0 && secondQueue.Count > 0 && turns < 1000000)
- {
- turns++;
- var firstCurrentCard = firstQueue.Dequeue();
- var firstPower = int.Parse(firstCurrentCard.Substring(0, firstCurrentCard.Length - 1));
- var secondCurrentCard = secondQueue.Dequeue();
- var secondPower = int.Parse(secondCurrentCard.Substring(0, secondCurrentCard.Length - 1));
- if (firstPower > secondPower)
- {
- firstQueue.Enqueue(firstCurrentCard);
- firstQueue.Enqueue(secondCurrentCard);
- }
- else if (firstPower < secondPower)
- {
- secondQueue.Enqueue(secondCurrentCard);
- secondQueue.Enqueue(firstCurrentCard);
- }
- else
- {
- while (firstQueue.Count >= 3 && secondQueue.Count >= 3)
- {
- var sb1 = new StringBuilder();
- var firstCard1 = firstQueue.Dequeue();
- var secondCard1 = firstQueue.Dequeue();
- var thirdCard1 = firstQueue.Dequeue();
- list.Add(firstCard1);
- list.Add(secondCard1);
- list.Add(thirdCard1);
- sb1.Append(firstCard1.Last());
- sb1.Append(secondCard1.Last());
- sb1.Append(thirdCard1.Last());
- var sum1 = 0;
- for (int i = 0; i < sb1.ToString().Length; i++)
- {
- sum1 += (int)(sb1.ToString()[i] - 96);
- }
- var sb2 = new StringBuilder();
- var firstCard2 = secondQueue.Dequeue();
- var secondCard2 = secondQueue.Dequeue();
- var thirdCard2 = secondQueue.Dequeue();
- sb2.Append(firstCard2.Last());
- sb2.Append(secondCard2.Last());
- sb2.Append(thirdCard2.Last());
- list.Add(firstCard2);
- list.Add(secondCard2);
- list.Add(thirdCard2);
- var sum2 = 0;
- for (int i = 0; i < sb2.ToString().Length; i++)
- {
- sum2 += (int)(sb2.ToString()[i] - 96);
- }
- list = list.OrderByDescending(x => x).ToList();
- if (sum1 > sum2)
- {
- for (int i = 0; i < list.Count; i++)
- {
- firstQueue.Enqueue(list[i]);
- }
- }
- else if (sum1 < sum2)
- {
- for (int i = 0; i < list.Count; i++)
- {
- secondQueue.Enqueue(list[i]);
- }
- }
- else
- {
- continue;
- }
- }
- }
- }
- if (turns== 1000000)
- {
- if (firstQueue.Count> secondQueue.Count)
- {
- Console.WriteLine($"First player wins after {turns} turns");
- }
- else if (firstQueue.Count < secondQueue.Count)
- {
- Console.WriteLine($"Second player wins after {turns} turns");
- }
- else
- {
- Console.WriteLine($"Draw after {turns} turns");
- }
- }
- else
- {
- if (firstQueue.Count > 0)
- {
- Console.WriteLine($"First player wins after {turns} turns");
- }
- else if (secondQueue.Count > 0)
- {
- Console.WriteLine($"Second player wins after {turns} turns");
- }
- else
- {
- Console.WriteLine($"Draw after {turns} turns");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement