Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main()
- {
- string cards = Console.ReadLine();
- var card = cards.Split(',');
- var players = new List<int>();
- foreach (var item in card)
- {
- players.Add(int.Parse(item));
- }
- Console.WriteLine(CardsWinner(players));
- string cakes = Console.ReadLine(); // Task 2
- int friends = int.Parse(Console.ReadLine());
- Console.WriteLine(BitesOfCake(cakes,friends));
- string coins = Console.ReadLine();
- Console.WriteLine(CalcTransactions(coins));
- }
- private static int CardsWinner(List<int> points)
- {
- int bestPoints = -1;
- int bestPlayer = -1;
- for (int i = 0; i < points.Count; i++)
- {
- if (points[i] > 21)
- {
- continue;
- }
- if (points[i] > bestPoints)
- {
- bestPoints = points[i];
- bestPlayer = i;
- }
- else if (points[i] == bestPoints)
- {
- bestPlayer = -1;
- }
- }
- return bestPlayer;
- }
- private static int BitesOfCake(string cake, int friends)
- {
- string[] cakes = cake.Split(',');
- Array.Sort(cakes);
- int bites = 0;
- int lenght = cakes.Length;
- for (int i = lenght - 1; i >= 0; i -= friends + 1)
- {
- bites += int.Parse(cakes[i]);
- }
- return bites;
- }
- private static int CalcTransactions(string coin)
- {
- string[] coins = coin.Split(' ');
- int G1 = int.Parse(coins[0]);
- int S1 = int.Parse(coins[1]);
- int B1 = int.Parse(coins[2]);
- int G2 = int.Parse(coins[3]);
- int S2 = int.Parse(coins[4]);
- int B2 = int.Parse(coins[5]);
- int exchangeOperations = 0;
- while (G2 > G1)
- {
- --G2;
- S2 += 11;
- exchangeOperations++;
- }
- while (S2 > S1)
- {
- if (G1 > G2)
- {
- --G1;
- S1 += 9;
- exchangeOperations++;
- }
- else
- {
- --S2;
- B2 += 11;
- exchangeOperations++;
- }
- }
- while (B2 > B1)
- {
- if (S1 > S2)
- {
- --S1;
- B1 += 9;
- exchangeOperations++;
- }
- else if (G1 > G2)
- {
- --G1;
- S1 += 9;
- exchangeOperations++;
- }
- else
- {
- return -1;
- }
- }
- return exchangeOperations;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement