svetlozar_kirkov

Gambling (100/100)

Nov 14th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Threading;
  5.  
  6. namespace Gambling
  7. {
  8.     class Gambling
  9.     {
  10.         static void Main()
  11.         {
  12.             Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  13.             decimal cash = decimal.Parse(Console.ReadLine());
  14.             decimal potValue = 2m*cash;
  15.             string houseHand = Console.ReadLine();
  16.             string[] houseCards = houseHand.Split(' ');
  17.             Dictionary<string,int> dict = new Dictionary<string, int>();
  18.             dict.Add("J",11);
  19.             dict.Add("Q",12);
  20.             dict.Add("K",13);
  21.             dict.Add("A",14);
  22.             string[] cardFaces = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
  23.             int[] cardValues = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
  24.             int houseStrength = 0;
  25.             int betterHandsCount = 0;
  26.             int allHands = 0;
  27.             for (int i = 0; i < 4; i++)
  28.             {
  29.                 if (dict.ContainsKey(houseCards[i]))
  30.                 {
  31.                     houseStrength += dict[houseCards[i]];
  32.                 }
  33.                 else
  34.                 {
  35.                     houseStrength += Convert.ToInt32(houseCards[i].ToString());
  36.                 }
  37.             }
  38.             for (int i = 0; i < cardFaces.Length; i++)
  39.             {
  40.                 for (int j = 0; j < cardFaces.Length; j++)
  41.                 {
  42.                     for (int k = 0; k < cardFaces.Length; k++)
  43.                     {
  44.                         for (int l = 0; l < cardFaces.Length; l++)
  45.                         {
  46.                             string[] tempCombo = {cardFaces[i], cardFaces[j], cardFaces[k], cardFaces[l]};
  47.                             if (tempCombo != houseCards)
  48.                             {
  49.                                 int tempWeight = cardValues[i] + cardValues[j] + cardValues[k] + cardValues[l];
  50.                                 if (tempWeight>houseStrength)
  51.                                 {
  52.                                     betterHandsCount++;
  53.                                     allHands++;
  54.                                 }
  55.                                 else
  56.                                 {
  57.                                     allHands++;
  58.                                 }
  59.                             }
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.             decimal percentage = GetPercentage(betterHandsCount, allHands);
  65.             if (percentage<50)
  66.             {
  67.                 Console.WriteLine("FOLD");
  68.             }
  69.             else
  70.             {
  71.                 Console.WriteLine("DRAW");
  72.             }
  73.             decimal expectedWinnings = (percentage*potValue)/100;
  74.             Console.WriteLine("{0:0.00}",Math.Round(expectedWinnings,2));
  75.  
  76.         }
  77.         public static Decimal GetPercentage(Int32 value, Int32 total)
  78.         {
  79.             Decimal percent = 0;
  80.  
  81.             if (value == 0 || total == 0)
  82.             {
  83.                 percent = 0;
  84.             }
  85.  
  86.             else
  87.             {
  88.                 percent = Decimal.Divide(value, total) * 100;
  89.             }
  90.  
  91.             return percent;
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment