Advertisement
Siropo

Poker hand

Dec 29th, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Poker
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             string[] handCards = new string[5];
  15.             int[] handCardsNum = new int[5];
  16.  
  17.             for (int i = 0; i < 5; i++)
  18.             {
  19.                 handCards[i] = Console.ReadLine();
  20.  
  21.                 if (handCards[i] == "A")
  22.                 {
  23.                     handCardsNum[i] = 1;
  24.                 }
  25.                 else if (handCards[i] == "J")
  26.                 {
  27.                     handCardsNum[i] = 11;
  28.                 }
  29.                 else if (handCards[i] == "Q")
  30.                 {
  31.                     handCardsNum[i] = 12;
  32.                 }
  33.                 else if (handCards[i] == "K")
  34.                 {
  35.                     handCardsNum[i] = 13;
  36.                 }
  37.                 else
  38.                 {
  39.                     bool result = Int32.TryParse(handCards[i], out handCardsNum[i]);
  40.                 }
  41.             }
  42.             Array.Sort(handCardsNum);
  43.  
  44.             int start = 0;
  45.             int firstLen = 1;
  46.             int secondLen = 1;
  47.             bool fillFirst = true;
  48.             string winHand = "";
  49.  
  50.             for (var i = 0; i < 5; i++)
  51.             {
  52.                 if (i != start)
  53.                 {
  54.                     if (handCardsNum[start] == handCardsNum[i])
  55.                     {
  56.                         if (fillFirst)
  57.                         {
  58.                             firstLen++;
  59.                         }
  60.                         else
  61.                         {
  62.                             secondLen++;
  63.                         }
  64.                     }
  65.                     else
  66.                     {
  67.                         if (firstLen != 1)
  68.                         {
  69.                             fillFirst = false;
  70.                         }
  71.                         start = i;
  72.                     }
  73.                 }
  74.             }
  75.  
  76.             if (handCardsNum[0] + 1 == handCardsNum[1] && handCardsNum[1] + 1 == handCardsNum[2] && handCardsNum[2] + 1 == handCardsNum[3]
  77.                 && handCardsNum[3] + 1 == handCardsNum[4])
  78.             {
  79.                 winHand = "Straight";
  80.             }
  81.             else if (firstLen == 5 || secondLen == 5)
  82.             {
  83.                 winHand = "Impossible";
  84.             }
  85.             else if (firstLen == 4)
  86.             {
  87.                 winHand = "Four of a Kind";
  88.             }
  89.             else if ((firstLen == 3 && secondLen == 2) || (firstLen == 2 && secondLen == 3))
  90.             {
  91.                 winHand = "Full House";
  92.             }
  93.             else if (firstLen == 3 || secondLen == 3)
  94.             {
  95.                 winHand = "Three of a Kind";
  96.             }
  97.             else if (firstLen == 2 && secondLen == 2)
  98.             {
  99.                 winHand = "Two Pairs";
  100.             }
  101.             else if (firstLen == 2)
  102.             {
  103.                 winHand = "One Pair";
  104.             }
  105.             else
  106.             {
  107.                 winHand = "Nothing";
  108.             }
  109.                 Console.WriteLine(winHand);
  110.             }
  111.  
  112.         }
  113.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement