Advertisement
psotirov

Poker

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