Advertisement
dimov

Untitled

Jan 3rd, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class Poker
  4. {
  5.     static void Main()
  6.     {
  7.  
  8.         string card;
  9.         int[] cardsInt = new int[5];
  10.  
  11.        
  12.  
  13.         for (int i = 0; i < 5; i++)
  14.         {
  15.             card = Console.ReadLine();
  16.             switch (card)
  17.             {
  18.                 case "J":
  19.                     card = "11";
  20.                     break;
  21.                 case "Q":
  22.                     card = "12";
  23.                     break;
  24.                 case "K":
  25.                     card = "13";
  26.                     break;
  27.                 case "A":
  28.                     card = "14";
  29.                     break;
  30.                 default:
  31.                     break;
  32.             }
  33.             cardsInt[i] = int.Parse(card);
  34.         }
  35.  
  36.         int counter = 0;
  37.         int sum = 0;
  38.         int flag = 0;
  39.  
  40.         for (int i = 0; i < 5; i++)
  41.         {
  42.             sum += cardsInt[i];                             //the sum for straight will always sum%5=0 or 28 for A,2,3,4,5
  43.             for (int j = (i+1); j < 5; j++)
  44.             {
  45.                
  46.                 if (cardsInt[i]==cardsInt[j])
  47.                 {
  48.                     counter++;                              //counter for the switch
  49.                    
  50.                 }
  51.                 if (cardsInt[i] != cardsInt[j])
  52.                 {
  53.                     flag++;                                 //make sure 5 cards are different
  54.                 }
  55.             }
  56.         }
  57.  
  58.         if (flag == 10 && ((sum % 5 == 0) || sum == 28))
  59.         {
  60.             Console.WriteLine("Straight");
  61.         }
  62.         else
  63.         {
  64.  
  65.             switch (counter)
  66.             {
  67.                 case 0:
  68.                     Console.WriteLine("Nothing");
  69.                     break;
  70.                 case 1:
  71.                     Console.WriteLine("One Pair");
  72.                     break;
  73.                 case 2:
  74.                     Console.WriteLine("Two Pairs");
  75.                     break;
  76.                 case 3:
  77.                     Console.WriteLine("Three of a Kind");
  78.                     break;
  79.                 case 4:
  80.                     Console.WriteLine("Full House");
  81.                     break;
  82.                 case 6:
  83.                     Console.WriteLine("Four of a Kind");
  84.                     break;
  85.                 case 10:
  86.                     Console.WriteLine("Impossible");
  87.                     break;
  88.                 default:
  89.                     Console.WriteLine("Nothing");
  90.                     break;
  91.               }
  92.          }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement