Advertisement
svetoslavbozov

Three in one (50/50)

Feb 13th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         string cards = Console.ReadLine();
  9.         var card = cards.Split(',');
  10.         var players = new List<int>();
  11.         foreach (var item in card)
  12.         {
  13.             players.Add(int.Parse(item));
  14.         }
  15.         Console.WriteLine(CardsWinner(players));
  16.  
  17.         string cakes = Console.ReadLine();              // Task 2      
  18.         int friends = int.Parse(Console.ReadLine());
  19.         Console.WriteLine(BitesOfCake(cakes,friends));
  20.  
  21.         string coins = Console.ReadLine();        
  22.         Console.WriteLine(CalcTransactions(coins));      
  23.     }
  24.     private static int CardsWinner(List<int> points)
  25.     {
  26.         int bestPoints = -1;
  27.         int bestPlayer = -1;
  28.  
  29.         for (int i = 0; i < points.Count; i++)
  30.         {
  31.             if (points[i] > 21)
  32.             {
  33.                 continue;
  34.             }
  35.             if (points[i] > bestPoints)
  36.             {
  37.                 bestPoints = points[i];
  38.                 bestPlayer = i;
  39.             }
  40.             else if (points[i] == bestPoints)
  41.             {
  42.                 bestPlayer = -1;
  43.             }
  44.         }
  45.         return bestPlayer;
  46.     }
  47.  
  48.     private static int BitesOfCake(string cake, int friends)
  49.     {
  50.         string[] cakes = cake.Split(',');
  51.         Array.Sort(cakes);
  52.         int bites = 0;
  53.         int lenght = cakes.Length;
  54.         for (int i = lenght - 1; i >= 0; i -= friends + 1)
  55.         {
  56.             bites += int.Parse(cakes[i]);
  57.         }
  58.         return bites;
  59.     }
  60.  
  61.     private static int CalcTransactions(string coin)
  62.     {
  63.         string[] coins = coin.Split(' ');
  64.         int G1 = int.Parse(coins[0]);
  65.         int S1 = int.Parse(coins[1]);
  66.         int B1 = int.Parse(coins[2]);
  67.         int G2 = int.Parse(coins[3]);
  68.         int S2 = int.Parse(coins[4]);
  69.         int B2 = int.Parse(coins[5]);
  70.  
  71.         int exchangeOperations = 0;
  72.         while (G2 > G1)
  73.         {
  74.             --G2;
  75.             S2 += 11;
  76.             exchangeOperations++;
  77.         }
  78.  
  79.         while (S2 > S1)
  80.         {
  81.             if (G1 > G2)
  82.             {
  83.                 --G1;
  84.                 S1 += 9;
  85.                 exchangeOperations++;
  86.             }
  87.             else
  88.             {
  89.                 --S2;
  90.                 B2 += 11;
  91.                 exchangeOperations++;
  92.             }
  93.         }
  94.  
  95.         while (B2 > B1)
  96.         {
  97.             if (S1 > S2)
  98.             {
  99.                 --S1;
  100.                 B1 += 9;
  101.                 exchangeOperations++;
  102.             }
  103.             else if (G1 > G2)
  104.             {
  105.                 --G1;
  106.                 S1 += 9;
  107.                 exchangeOperations++;
  108.             }
  109.             else
  110.             {
  111.                 return -1;
  112.             }
  113.         }
  114.  
  115.         return exchangeOperations;
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement