archangelmihail

Poker

Nov 30th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.05 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 Poker
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] cards = new int[13]; // 2, 3, 4 ... J, Q, K, A
  14.  
  15.             for (int i = 0; i < 5; i++)
  16.             {
  17.                 string card = Console.ReadLine();
  18.  
  19.                 switch (card)
  20.                 {
  21.                     case "10": cards[8]++; break;
  22.                     case "J": cards[9]++; break;
  23.                     case "Q": cards[10]++; break;
  24.                     case "K": cards[11]++; break;
  25.                     case "A": cards[12]++; break;
  26.                     default: cards[int.Parse(card) - 2]++; break;
  27.                 }
  28.             }
  29.  
  30.             int twoOfAKind = 0;
  31.             bool threeOfAKind = false;
  32.             bool fourOfAKind = false;
  33.             bool fiveOfAKind = false;
  34.             bool straight = false;
  35.  
  36.             for (int i = 0; i < cards.Length - 4; i++)
  37.             {
  38.                 if (cards[i] == 1 && cards[i + 1] == 1 &&
  39.                     cards[i + 2] == 1 && cards[i + 3] == 1 && cards[i + 4] == 1)
  40.                 {
  41.                     straight = true;
  42.                     break;
  43.                 }
  44.  
  45.                 if (cards[0] == 1 && cards[1] == 1 &&
  46.                     cards[2] == 1 && cards[3] == 1 && cards[12] == 1)
  47.                 {
  48.                     straight = true;
  49.                     break;
  50.                 }
  51.             }
  52.  
  53.             for (int i = 0; i < cards.Length && !straight; i++)
  54.             {
  55.                 if (cards[i] == 5)
  56.                 {
  57.                     fiveOfAKind = true;
  58.                     break;
  59.                 }
  60.                 else if (cards[i] == 4)
  61.                 {
  62.                     fourOfAKind = true;
  63.                     break;
  64.                 }
  65.                 else if (cards[i] == 3)
  66.                 {
  67.                     threeOfAKind = true;
  68.                 }
  69.                 else if (cards[i] == 2)
  70.                 {
  71.                     ++twoOfAKind;
  72.                 }
  73.             }
  74.  
  75.             if (fiveOfAKind)
  76.             {
  77.                 Console.WriteLine("Impossible");
  78.             }
  79.             else if (fourOfAKind)
  80.             {
  81.                 Console.WriteLine("Four of a Kind");
  82.             }
  83.             else if (threeOfAKind && twoOfAKind == 1)
  84.             {
  85.                 Console.WriteLine("Full House");
  86.             }
  87.             else if (straight)
  88.             {
  89.                 Console.WriteLine("Straight");
  90.             }
  91.             else if (threeOfAKind)
  92.             {
  93.                 Console.WriteLine("Three of a Kind");
  94.             }
  95.             else if (twoOfAKind == 2)
  96.             {
  97.                 Console.WriteLine("Two Pairs");
  98.             }
  99.             else if (twoOfAKind == 1)
  100.             {
  101.                 Console.WriteLine("One Pair");
  102.             }
  103.             else
  104.             {
  105.                 Console.WriteLine("Nothing");
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment