Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Poker
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] handCards = new string[5];
- int[] handCardsNum = new int[5];
- for (int i = 0; i < 5; i++)
- {
- handCards[i] = Console.ReadLine();
- if (handCards[i] == "A")
- {
- handCardsNum[i] = 1;
- }
- else if (handCards[i] == "J")
- {
- handCardsNum[i] = 11;
- }
- else if (handCards[i] == "Q")
- {
- handCardsNum[i] = 12;
- }
- else if (handCards[i] == "K")
- {
- handCardsNum[i] = 13;
- }
- else
- {
- bool result = Int32.TryParse(handCards[i], out handCardsNum[i]);
- }
- }
- Array.Sort(handCardsNum);
- int start = 0;
- int firstLen = 1;
- int secondLen = 1;
- bool fillFirst = true;
- string winHand = "";
- for (var i = 0; i < 5; i++)
- {
- if (i != start)
- {
- if (handCardsNum[start] == handCardsNum[i])
- {
- if (fillFirst)
- {
- firstLen++;
- }
- else
- {
- secondLen++;
- }
- }
- else
- {
- if (firstLen != 1)
- {
- fillFirst = false;
- }
- start = i;
- }
- }
- }
- if (handCardsNum[0] + 1 == handCardsNum[1] && handCardsNum[1] + 1 == handCardsNum[2] && handCardsNum[2] + 1 == handCardsNum[3]
- && handCardsNum[3] + 1 == handCardsNum[4])
- {
- winHand = "Straight";
- }
- else if (firstLen == 5 || secondLen == 5)
- {
- winHand = "Impossible";
- }
- else if (firstLen == 4)
- {
- winHand = "Four of a Kind";
- }
- else if ((firstLen == 3 && secondLen == 2) || (firstLen == 2 && secondLen == 3))
- {
- winHand = "Full House";
- }
- else if (firstLen == 3 || secondLen == 3)
- {
- winHand = "Three of a Kind";
- }
- else if (firstLen == 2 && secondLen == 2)
- {
- winHand = "Two Pairs";
- }
- else if (firstLen == 2)
- {
- winHand = "One Pair";
- }
- else
- {
- winHand = "Nothing";
- }
- Console.WriteLine(winHand);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement