Problem:


ポーカー

ポーカーの手札データを読み込んで、それぞれについてその役を出力するプログラムを作成してください。ただし、この問題では、以下のルールに従います。

ポーカーはトランプ 5 枚で行う競技です。

同じ数字のカードは 5 枚以上ありません。

ジョーカーは無いものとします。

以下のポーカーの役だけを考えるものとします。(番号が大きいほど役が高くなります。)

役なし(以下に挙げるどれにも当てはまらない)

ワンペア（2 枚の同じ数字のカードが1 組ある）

ツーペア（2 枚の同じ数字のカードが2 組ある）

スリーカード（3 枚の同じ数字のカードが1 組ある）

ストレート（5 枚のカードの数字が連続している）

ただし、A を含むストレートの場合、A で終わる並びもストレートとします。つまり、A を含むストレート
は、A 2 3 4 5 　と　10 J Q K A 　の２種類です。J Q K A 2 などのように、A をまたぐ並び
はストレートではありません。（この場合、「役なし」になります）。

フルハウス（3 枚の同じ数字のカードが1 組と、残りの2 枚が同じ数字のカード）

フォーカード（4 枚の同じ数字のカードが1 組ある）

Input

入力は複数のデータセットからなります。各データセットは以下の形式で与えられます。

手札1,手札2,手札3,手札4,手札5

手札は、トランプのJ(ジャック) を11、Q(クイーン) を12、K(キング) を13、A（エース）を 1、その他はそれぞれの数字で表すこととします。

データセットの数は 50 を超えません。

Output

データセットごとに、手札によってできる最も高い役をひとつ出力してください。役の表記については出力例に従ってください。

Sample Input

1,2,3,4,1
2,3,2,3,12
12,13,11,12,12
7,6,7,6,7
3,3,2,3,3
6,7,8,9,10
11,12,10,1,13
11,12,13,1,2

Output for the Sample Input

one pair
two pair
three card
full house
four card
straight
straight
null

3 3 2 3 3 という手札であったときは、two pair ではなく four card です。



Sample input:
1,2,3,4,1
2,3,2,3,12
12,13,11,12,12
7,6,7,6,7
3,3,2,3,3
6,7,8,9,10
11,12,10,1,13
11,12,13,1,2


Sample output:
one pair
two pair
three card
full house
four card
straight
straight
null

Submission status: Accepted

Solution code:
from collections import Counter
import sys

for line in sys.stdin:
    card = sorted(list(map(int, line.split(','))))
    pair = Counter(card).most_common()

    if pair[0][1] == 4:
        print('four card')
    elif pair[0][1] == 3 and pair[1][1] == 2:
        print('full house')
    elif pair[0][1] == 3:
        print('three card')
    elif pair[0][1] == pair[1][1] == 2:
        print('two pair')
    elif pair[0][1] == 2:
        print('one pair')
    elif [x - card[0] for x in card] == [0,1,2,3,4] or card == [1,10,11,12,13]:
        print('straight')
    else:
        print('null')

Submission status: Accepted

Solution code:
def straight(cards):
    if cards==[1,10,11,12,13]:
        return 1
    else:
        for i in range(1,5):
           if cards[i] != cards[i-1] + 1 :
               return 0
        return 1       

while True:
    try:
        cards = sorted(list(map(int, input().split(','))))
    except:
        break
    if cards.count(cards[1])==4:
        print('four card')
        continue
    elif len(set(cards))==2:
        print('full house')
        continue
    elif straight(cards)==1:
        print('straight')
        continue
    elif cards.count(cards[2])==3:
        print('three card')
        continue
    elif len(set(cards))==3:
        print('two pair')
        continue
    elif len(set(cards))==4:
        print('one pair')
        continue
    else:
        print('null')
        continue

Submission status: Accepted

Solution code:
while True:
    try:
        A = sorted(list(map(int, input().split(","))))
        _sum = 0
        _max = 0
        for i in range(1,14):
            tmp = A.count(i)
            if tmp > 1:
                _sum+=tmp
            _max = max(_max, tmp)
        if _max == 4:
            print("four card")
        elif _max == 3 and _sum == 5:
            print("full house")
        elif A.count(1) == 1 and (A[0] == 1 and A[2]-1 == A[3]-2 == A[4]-3 == A[1]) \
            or (A[4] == 1 and A[1]-1 == A[2]-2 == A[3] == A[0]):
            print("straight")
        elif A[1]-1 == A[2]-2 == A[3]-3 == A[4]-4 == A[0]:
            print("straight")
        elif _max == 3:
            print("three card")
        elif _sum == 4:
            print("two pair")
        elif _max == 2:
            print("one pair")
        else:
            print("null")
    except:
        break

Submission status: Accepted

Solution code:
straight = '12345678910111213110111213'

while True:
    try:
        lst = list(map(int, input().split(',')))
        lst.sort()
        clst = []

        for i in lst:
            clst.append(lst.count(i))

        if clst.count(4) == 4:
            print('four card')

        elif clst.count(3) == 3:
            if clst.count(2) == 2:
                print('full house')
            else:
                print('three card')
        elif clst.count(2) == 4:
            print('two pair')
        elif clst.count(2) == 2:
            print('one pair')
        else:
            s = str(lst[0]) + str(lst[1]) + str(lst[2]) + str(lst[3]) + str(lst[4])
            if s in straight:
                print('straight')
            else:
                print('null')
    
    except EOFError:
        break

Submission status: Accepted

Solution code:
def fourcard(card) :
    if card.count(card[0]) == 4 or card.count(card[1]) == 4 :
        return True
    else :
        return False

def fullhouse(card) :
    card.sort()
    if (card[0] ==  card[1] == card[2] and card[3] == card[4]) or (card[0] == card[1] and card[2] == card[3] == card[4]) :
        return True
    else :
        return False
        
def straight(card) :
    card.sort()
    if card[0] == 1 and card[1] == 10 and card[2] == 11 and  card[3] == 12 and card[4] == 13 :
        return True
    else :
        ans = 'True'
        for i in range(4) :
            if card[i] + 1 != card[i + 1] :
                ans = False
        if ans == 'True' :
            return True
        else :
            return False

def threecard(card) :
    if card.count(card[0]) == 3 or card.count(card[1]) == 3 or card.count(card[2]) == 3 :
        return True
    else :
        return False
def twopair(card) :
    card.sort()
    if card[0] == card[1] :
        if card[2] == card[3] or card[3] == card[4]:
            return True
    elif card[1] == card[2] :
        if card[3] == card[4] :
            return True
    else :
        return False
def onepair(card) :
    card.sort()
    if card[0] == card[1] or card[1] == card[2] or card[2] == card[3] or card[3] == card[4] :
        return True
    else :
        return False


while True :
    try :
        card = list(map(int, input().split(',')))
    except EOFError :
        break
    
    if fourcard(card) :
        print('four card')
    elif fullhouse(card) :
        print('full house')
    elif straight(card) :
        print('straight')
    elif threecard(card) :
        print('three card')
    elif twopair(card) :
        print('two pair')
    elif onepair(card) :
        print('one pair')
    else :
        print('null')

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve(C):
    d = {}
    for c in C:
        d[c] = d.get(c, 0) + 1
    *vs, = d.values()
    vs.sort()
    if vs[-1] == 4:
        return "four card"
    if vs == [2, 3]:
        return "full house"
    c0 = C[0]
    if C == list(range(c0, c0+5)) or C == [1, 10, 11, 12, 13]:
        return "straight"
    if vs == [1, 1, 3]:
        return "three card"
    if vs == [1, 2, 2]:
        return "two pair"
    if vs == [1, 1, 1, 2]:
        return "one pair"
    return "null"

for line in readlines():
    *C, = map(int, line.split(","))
    C.sort()
    write("%s\n" % solve(C))

Submission status: Accepted

Solution code:
words = [['null','one pair','three card','four card'], ['','','two pair','full house']]

while True:
    try:
        cards = list(int(x) for x in input().split(","))
        cards = sorted(cards,reverse=False)
        isStright = True
        pairCard = -1
        pairNum = 0
        pairIndex = 0
        
        tmp = cards[0]
        for i in range(1,5):
            if tmp + 1 != cards[i]:
                isStright = False
            if tmp == cards[i]:
                if pairNum >= 1 and pairCard != cards[i]:
                    pairIndex = 1
                pairNum += 1
                pairCard = cards[i]
            tmp = cards[i]
                
        if isStright or (cards[0] == 1 and cards[1] == 10 and cards[2] == 11 and cards[3] == 12 and cards[4] == 13):
            ans = "straight"
        else:
            ans = words[pairIndex][pairNum]
        print(ans)
    except:
        break

Submission status: Accepted

Solution code:
from collections import Counter

def checkStraint(hand):
    hand=sorted(hand)
    if set(hand)==set([10,11,12,13,1]):
        return True
    for i in range(5):
        if hand[0]+i==hand[i]:
            continue
        else:
            return False
    return True

while True:
    try:
        hand=[int(i) for i in input().split(",")]
        hand=sorted(hand)
        c=Counter(hand)
        c=sorted(dict(c).items(),key=lambda w:w[1],reverse=True)
        if c[0][1]==4:
            print("four card")
            continue
        elif c[0][1]==3 and c[1][1]==2:
            print("full house")
            continue

        elif checkStraint(hand):
            print("straight")
            continue
        elif c[0][1]==3:
            print("three card")
            continue
        elif c[0][1]==2 and c[1][1]==2:
            print("two pair")
            continue
        elif c[0][1]==2:
            print("one pair")
            continue
        else:
            print("null")

    except EOFError:
        break

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n   

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート（代入する必要なし）
# N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            #N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
            #N.append([int(x) for x in input().split()])
            N.append([int(x) for x in input().split(',')])
        except EOFError:
            break
    return N

### 0038

D = get_input()

for d in D:
    ans = "null"
    
    L = [0 for x in range(13)]
    for i in d:
        L[i-1] += 1

    if 4 in L:
        ans = "four card"
    elif 3 in L:
        if 2 in L:
            ans = "full house"
        else:
            ans = "three card"
    elif 2 in L:
        if L.count(2)==2:
            ans = "two pair"
        else:
            ans = "one pair"
    else:
        d.sort()
        d = [x-min(d) for x in d]
        if d == [0,1,2,3,4]:
            ans = "straight"
        elif d == [0,9,10,11,12]:
            ans = "straight"
    
    print(ans)

Submission status: Accepted

Solution code:
import collections

def solution1(kard):
    #強いものから順に探していく
    if fourcard(kard):
        print("four card")
    elif fullhouse(kard):
        print("full house")
    elif straight(kard):
        print("straight")
    elif threecard(kard):
        print("three card")
    elif twopair(kard):
        print("two pair")
    elif onepair(kard):
        print("one pair")
    else:
        print("null")

def fourcard(kard):
    if kard.count(kard[0])==4 or kard.count(kard[1])==4:
        return True
    else:
        return False

def fullhouse(kard):
    list=collections.Counter(kard)
    if len(list)==2:
        return True
    else:
        return False

def straight(kard):
    c=sorted(kard,reverse=True)
    if c[0]==(c[1]+1)==(c[2]+2)==(c[3]+3)==(c[4]+4) or (c[0]==(c[1]+1)==(c[2]+2)==(c[3]+3) and c[4]==1 and c[0]==13):
        return True
    else:
        return False
    

def threecard(kard):
    if kard.count(kard[0])==3 or kard.count(kard[1])==3 or kard.count(kard[2])==3:
        return True
    else:
        return False
    
def twopair(kard):
    list=collections.Counter(kard)
    if len(list)==3:
        return True
    else:
        return False

def onepair(kard):
    list=collections.Counter(kard)
    if len(list)==4:
        return True
    else:
        return False


while True:
    try:
        kard=list(map(int,input().split(",")))
    except:
        break
    solution1(kard)

Submission status: Accepted

Solution code:
import collections

def judge(card, cnt):
    nmax = cnt[0][1]
    if nmax == 4: return "four card"
    if nmax == 3: return "full house" if cnt[1][1] == 2 else "three card"
    if nmax == 2: return "two pair" if cnt[1][1] == 2 else "one pair"
    if (card[0] == 1 and list(range(10, 14)) == card[1:]) or list(range(card[0], card[0] + 5)) == card : return "straight"

    return "null"
while True:
    try:
        card = list(map(int, input().split(",")))
    except:
        break
    cnt = collections.Counter(card)
    print(judge(sorted(card), sorted(cnt.items(), key = lambda x:-x[1])))

Submission status: Accepted

Solution code:

def chk_all(A):
	s_A = set(A)
	B = list(s_A)
	leng = len(s_A)
	if leng == 2:
		if A.count(B[0]) == 4 or A.count(B[1]) == 4:
			return "four card"
		else:
			return "full house"
	elif leng == 3:
		if A.count(B[0]) == 3 or A.count(B[1]) == 3 or A.count(B[2]) == 3:
			return "three card"
		else:
			return "two pair"
	elif leng == 4:
		return "one pair"
	else:
		A = sorted(A)

		if A[0] == 1 and A[1] == 10 and A[2] == 11 and A[3] == 12 and A[4] == 13:
			return "straight"

		for i in range(1,5):
			if A[i] - A[i-1] != 1:
				return "null"

		return "straight"

	return "null"

if __name__ == '__main__':

	while True:
		try:
			A = list(map(int,input().split(",")))
			print(chk_all(A))

		except EOFError:
			break

Submission status: Accepted

Solution code:
def yaku(N):
    n=N[0]
    li=[]
    for i in range(5):
        li.append(n)
        n +=1
    if N==li or N==[1,10,11,12,13]:
        print("straight")
        return
    mp={}
    count_2=0
    count_3=0
    for i in N:
        if i in mp:
            mp[i] +=1
        else:
            mp[i]=1
    co=0
    for k,v in mp.items():
        if v!=1:
            if v==2:
                count_2 +=1
            elif v==3:
                count_3 +=1
            else:
                print("four card")
                return
        else:
            co +=1
            if co==5:
                print("null")
                return
    if count_2==1 and count_3==1:
        print("full house")
    elif count_3==1:
        print("three card")
    elif count_2==2:
        print("two pair")
    elif count_2==1:
        print("one pair")
        
while True:
    try:
        N=sorted(list(map(int,input().split(","))))
        yaku(N)
    except:break

Submission status: Accepted

Solution code:
while 1:
    try:
        hand=list(map(int,input().split(",")))
        hand.sort()
        if len(list(set(hand)))==2:
            if hand.count(hand[0])==4 or hand.count(hand[4])==4:print("four card")
            else:print("full house")
        elif hand[0]+1==hand[1] and hand[1]+1==hand[2] and hand[2]+1==hand[3] and hand[3]+1==hand[4]:print("straight")
        elif hand[0]==1 and hand[1]==10 and hand[2]==11 and hand[3]==12 and hand[4]==13:print("straight")
        elif len(list(set(hand)))==3:
            if hand.count(hand[0])==3 or hand.count(hand[2])==3 or hand.count(hand[4])==3:print("three card")
            else:print("two pair")
        elif len(list(set(hand)))==4:print("one pair")
        else:print("null")        
    except:break

Submission status: Accepted

Solution code:
while(1):
    try:
        a = [int(i) for i in input().split(",")]
        a.sort()
        pairs = []
        for i in set(a):
            count = 0
            for j in a:
                if j == i:
                    count += 1
            pairs.append(count)
        if 5 in pairs:
            print("full house")
        elif 4 in pairs:
            print("four card")
        elif 3 in pairs and 2 in pairs:
            print("full house")
        elif 3 in pairs:
            print("three card")
        elif pairs.count(2) == 2:
            print("two pair")
        elif 2 in pairs:
            print("one pair")
        elif [a[i+1] - a[i] for i in range(4)] == [1 for i in range(4)] or a == [1,10,11,12,13]:
            print("straight")
        else:
            print("null")
    except EOFError:
        break

Submission status: Accepted

Solution code:
import collections

while 1:
    try:
        hand = list(map(int, input().split(",")))
    except:
        break

    chand = collections.Counter(hand)
    count = chand.most_common()

    straight = [1, 10, 11, 12, 13]

    if count[0][1] == 4:
        print("four card")
        continue
    elif count[0][1] == 3 and count[1][1] == 2:
        print("full house")
        continue
    else:
        hand.sort()
        if hand == straight:
            print("straight")
            continue
        else:
            check = True
            for i in range(len(hand)-1):
                if hand[i+1] - hand[i] != 1:
                    check = False
            if check:
                print("straight")
                continue
    if count[0][1] == 3:
        print("three card")
        continue
    elif count[0][1] == count[1][1] == 2:
        print("two pair")
        continue
    elif count[0][1] == 2:
        print("one pair")
        continue
    else:
        print("null")

Submission status: Accepted

Solution code:
from collections import Counter

def is_straight(game):
    if 1 in game:
        if game == [1, 2, 3, 4, 5] or game == [1, 10, 11, 12, 13]:
            return True
        else:
            return False
    else:
        for i in range(len(game)-1):
            if game[i+1] != game[i]+1:
                return False
            return True

while True:
    try: start = input()
    except: break

    game = list(map(int, start.split(',')))
    game.sort()
    result = Counter(game)
    values, counts = zip(*result.most_common())

    if counts[0] == 2:
        if len(counts) == 4:
            print('one pair')
        else:
            print('two pair')
    elif counts[0] == 3:
        if len(counts) == 3:
            print('three card')
        else:
            print('full house')
    elif counts[0] == 4:
        print('four card')
    elif is_straight(game):
        print('straight')
    else:
        print('null')

Submission status: Accepted

Solution code:
import sys

def check(cards):
    ones, twos, threes, fours = 0, 0, 0, 0
    for i in range(1, 14):
        c = cards.count(i)
        if c == 1: ones += 1
        elif c == 2: twos += 1
        elif c == 3: threes += 1
        elif c == 4: fours += 1
    
    if fours:
        return 'four card'
    if threes and twos:
        return 'full house'
    if ones == 5:
        for i, v in enumerate(cards[:-1]):
            if not v == cards[i + 1] - 1:
                break
        else: return 'straight'
        if cards == [1, 10, 11, 12, 13]:
            return 'straight'
    if threes:
        return 'three card'
    if twos == 2:
        return 'two pair'
    if twos:
        return 'one pair'
    return 'null'

def solve():
    for line in sys.stdin:
        cards = sorted(map(int, line.split(',')))
        print(check(cards))

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import sys

def is_onepair(x):
    for i in range(4):
        if x.count(x[i]) == 2:
            return True

    return False

def is_twopair(x):
    count = 0
    for e in x:
        for e2 in x:
            if e == e2:
                count += 1
            if count == 2:
                return True

    return False

def is_threecard(x):
    for i in range(3):
        if x.count(x[i]) == 3:
            return True

    return False

def is_straight(x):
    x.sort()
    if x[0] == 1 and x[1:] = [10, 11, 12, 13]:
        return True
    for i in range(4):
        if x[i]+1 != x[i+1]:
            return False
    
    return True

def is_fullhouse(x):
    if is_threecard(x) and is_onepair(x):
        return True

    return False
    
def is_fourcard(x):
    for i in range(2):
        if x.count(x[i]) == 4:
            return True

    return False

for line in sys.stdin.readlines():
    hand = list(map(int, line.split(',')))
    if is_fourcard(hand):
        print("four card")
    elif is_fullhouse(hand):
        print("full house")
    elif is_straight(hand):
        print("straight")
    elif is_threecard(hand):
        print("three card")
    elif is_twopair(hand):
        print("two pair")
    elif is_onepair(hand):
        print("one pair")
    else:
        print("null")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def is_four_card(d):
    return 4 in d.values()


def is_full_house(d):
    return 3 in d.values() and 2 in d.values()


def is_straight(d):
    flag = [False, 0]
    for i in d.values():
        if flag[0] == True and flag[1] == 5:
            return True

        if i == 1:
            flag[0] = True
            flag[1] += 1
    return False


def is_three_card(d):
    return 3 in d.values()


def is_two_pair(d):
    return list(d.values()).count(2) == 2


def is_one_pair(d):
    return list(d.values()).count(2) == 1


def judge(d):
    if is_four_card(d):
        print('four card')
    elif is_full_house(d):
        print('full house')
    elif is_straight(d):
        print('straight')
    elif is_three_card(d):
        print('three card')
    elif is_two_pair(d):
        print('two pair')
    elif is_one_pair(d):
        print('one pair')
    else:
        print('null')


def solve(cards):
    d = {k: 0 for k in range(1, 14)}
    for card in cards:
        d[card] += 1
    judge(d)

_input = input().split(",")
solve(_input)

Submission status: Runtime Error

Solution code:
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[4]-e[0]==4 or e[0]*10==e[1]],'one pair','two pair','three card','full house',0,'four card'][(sum(e.count(s)for s in e)//2-2])

Submission status: Runtime Error

Solution code:
while True:
      try:
            hand = sorted(map(int, raw_input().split(",")))
            kind = len(set(hand))
            ma = max([hand.count(i) for i in hand])
            if kind == 4:
                  print "one pair"
            elif kind == 3:
                  if ma == 2:
                        print "two pair"
                  else:
                        print "three card"
            elif kind == 2:
                  if ma==4:
                        print "four card"
                  else:
                  print "full house"
            else:
                  if hand==[1,10,11,12,13] or hand[4] - hand[0] == 4:
                        print "straight"
                  else:
                        print "null"
      except:
            break