본문 바로가기
Algorithm/Baekjoon

Baekjoon 16408 Poker Hand JAVA

by Hunveloper 2022. 4. 15.
728x90
 

16408번: Poker Hand

Output, on a single line, the strength of your hand.

www.acmicpc.net

문제

You are given a five-card hand drawn from a standard 52-card deck. The strength of your hand is the maximum value k such that there are k cards in your hand that have the same rank.

Compute the strength of your hand.

입력

The input will consist of a single line, with five two-character strings separated by spaces.

The first character in each string will be the rank of the card, and will be one of A23456789TJQK. The second character in the string will be the suit of the card, and will be one of CDHS.

You may assume all the strings are distinct.

출력

Output, on a single line, the strength of your hand.

풀이

같은 숫자를 몇개를 들고 있는지 찾는 문제이다.

입력받은 문자를 파싱하여 숫자부분만 카운팅해서 가장 많이 카운팅 된 갯수를 출력한다.

코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine());

		int[] ranks = new int[14];
		for (int i = 0; i < 5; i++) {
			String str = st.nextToken();

			if (str.charAt(0) == 'A')
				ranks[1]++;
			else if ('2' <= str.charAt(0) && str.charAt(0) <= '9')
				ranks[str.charAt(0) - '0']++;
			else if (str.charAt(0) == 'T')
				ranks[10]++;
			else if (str.charAt(0) == 'J')
				ranks[11]++;
			else if (str.charAt(0) == 'Q')
				ranks[12]++;
			else if (str.charAt(0) == 'K')
				ranks[13]++;
		}
		int max=0;
		for(int i=1;i<14;i++)
			max=Math.max(max, ranks[i]);
		System.out.println(max);
	}
}

 

728x90
728x90

댓글