Advertisement
Teodor92

Poker

Dec 30th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. class ProblemThree
  7. {
  8.     static void Main()
  9.     {
  10.         //input
  11.         List<int> allCards = new List<int>();
  12.         for (int i = 0; i < 5; i++)
  13.         {
  14.             string input = Console.ReadLine();
  15.             switch (input)
  16.             {
  17.                 case "J": allCards.Add(11); break;
  18.                 case "Q": allCards.Add(12); break;
  19.                 case "K": allCards.Add(13); break;
  20.                 case "A": allCards.Add(14); break;
  21.                 default: allCards.Add(int.Parse(input)); break;
  22.             }
  23.         }
  24.         // helpers
  25.         allCards.Sort();
  26.         int equalsNum = 1;
  27.         int numsOfPairs = 0;
  28.         int numsOfTipples = 0;
  29.         int numsOfFours = 0;
  30.         for (int i = 0; i < allCards.Count - 1; i++)
  31.         {
  32.             if (allCards[i] == allCards[i + 1])
  33.             {
  34.                 equalsNum++;
  35.             }
  36.             else
  37.             {
  38.                 if (equalsNum == 2)
  39.                 {
  40.                     numsOfPairs++;
  41.                 }
  42.                 else if (equalsNum == 3)
  43.                 {
  44.                     numsOfTipples++;
  45.                 }
  46.                 else if (equalsNum == 4)
  47.                 {
  48.                     numsOfFours++;
  49.                 }
  50.                 equalsNum = 1;
  51.             }
  52.         }
  53.         // last case
  54.         if (equalsNum == 2)
  55.         {
  56.             numsOfPairs++;
  57.         }
  58.         else if (equalsNum == 3)
  59.         {
  60.             numsOfTipples++;
  61.         }
  62.         else if (equalsNum == 4)
  63.         {
  64.             numsOfFours++;
  65.         }
  66.         //straight checker
  67.         bool isStraight = true;
  68.         for (int i = 0; i < allCards.Count - 1; i++)
  69.         {
  70.             if (allCards[i] + 1 != allCards[i + 1])
  71.             {
  72.                 isStraight = false;
  73.             }
  74.             if (allCards[0] == 2 && allCards[1] == 3 && allCards[2] == 4 && allCards[3] == 5 && allCards[4] == 14)
  75.             {
  76.                 isStraight = true;
  77.             }
  78.         }
  79.         // checks
  80.         if (allCards[0] == allCards[1] && allCards[1] == allCards[2] && allCards[2] == allCards[3] && allCards[3] == allCards[4])
  81.         {
  82.             Console.WriteLine("Impossible");
  83.         }
  84.         else if(numsOfFours == 1)
  85.         {
  86.             Console.WriteLine("Four of a Kind");
  87.         }
  88.         else if(numsOfPairs == 1 && numsOfTipples == 1)
  89.         {
  90.             Console.WriteLine("Full House");
  91.         }
  92.         else if (isStraight)
  93.         {
  94.             Console.WriteLine("Straight");
  95.         }
  96.         else if (numsOfTipples == 1)
  97.         {
  98.             Console.WriteLine("Three of a Kind");
  99.         }
  100.         else if (numsOfPairs == 2)
  101.         {
  102.             Console.WriteLine("Two Pairs");
  103.         }
  104.         else if( numsOfPairs == 1)
  105.         {
  106.             Console.WriteLine("One Pair");
  107.         }
  108.         else
  109.         {
  110.             Console.WriteLine("Nothing");
  111.         }
  112.         //for (int i = 0; i < allCards.Count; i++)
  113.         //{
  114.         //    Console.WriteLine(allCards[i]);
  115.         //}
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement