Advertisement
vic_alexiev

Poker.cs

Dec 31st, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Poker
  6. {
  7.     static void Main()
  8.     {
  9.         int[] cards = new int[5];
  10.         Dictionary<string, int> cardsDic = new Dictionary<string, int>();
  11.         cardsDic.Add("A", 0);
  12.  
  13.         for (int i = 2; i <= 10; i++)
  14.         {
  15.             cardsDic.Add(i.ToString(), 0);
  16.         }
  17.  
  18.         cardsDic.Add("J", 0);
  19.         cardsDic.Add("Q", 0);
  20.         cardsDic.Add("K", 0);
  21.  
  22.         for (int i = 0; i < 5; i++)
  23.         {
  24.             string card = Console.ReadLine();
  25.             cardsDic[card]++;
  26.  
  27.             switch (card)
  28.             {
  29.                 case "A":
  30.                     cards[i] = 1;
  31.                     break;
  32.                 case "J":
  33.                     cards[i] = 11;
  34.                     break;
  35.                 case "Q":
  36.                     cards[i] = 12;
  37.                     break;
  38.                 case "K":
  39.                     cards[i] = 13;
  40.                     break;
  41.                 default:
  42.                     cards[i] = Int32.Parse(card);
  43.                     break;
  44.             }
  45.         }
  46.  
  47.         if (cardsDic.ContainsValue(5))
  48.         {
  49.             Console.WriteLine("Impossible");
  50.         }
  51.         else if (cardsDic.ContainsValue(4))
  52.         {
  53.             Console.WriteLine("Four of a Kind");
  54.         }
  55.         else if (cardsDic.ContainsValue(3) && cardsDic.ContainsValue(2))
  56.         {
  57.             Console.WriteLine("Full House");
  58.         }
  59.         else if (cardsDic.ContainsValue(3))
  60.         {
  61.             Console.WriteLine("Three of a Kind");
  62.         }
  63.         else if (cardsDic.Count(c => c.Value == 2) == 2)
  64.         {
  65.             Console.WriteLine("Two Pairs");
  66.         }
  67.         else if (cardsDic.ContainsValue(2))
  68.         {
  69.             Console.WriteLine("One Pair");
  70.         }
  71.         else
  72.         {
  73.             Array.Sort(cards);
  74.  
  75.             for (int i = 0; i < 4; i++)
  76.             {
  77.                 if (!(cards[i] == cards[i + 1] - 1
  78.                     || cards[i] == 1 && cards[i + 1] == 10))
  79.                 {
  80.                     Console.WriteLine("Nothing");
  81.                     return;
  82.                 }
  83.             }
  84.  
  85.             Console.WriteLine("Straight");
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement