※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26564번 문제인 Poker Hand이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26564
26564번: Poker Hand
You're given a five-card hand drawn from a standard 52-card deck. Each card has a rank (one of A, 2, 3, . . . , 9, T, J, Q, K), and a suit (one of C, D, H, S).The strength of your hand is defined as the maximum value k such that there are k cards in your h
www.acmicpc.net
각 다섯개의 문자열을 읽어 rank(문자열의 첫번째 문자로 나타낸다)별 개수를 세는 배열을 이용해 가장 많은 rank의 개수를 세어 문제를 해결하자.
아래와 같은 cnt배열을 이용하면 구현을 간결하게 할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int T;
int cnt[128];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
memset(cnt, 0, sizeof(cnt));
int ans = 0;
for (int i = 0; i < 5; i++) {
string s; cin >> s;
char c = s[0];
cnt[c]++;
ans = max(ans, cnt[c]);
}
cout << ans << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 16911 // C++] 그래프와 쿼리 (0) | 2022.12.22 |
---|---|
[BOJ 26533 // C++] Tractor Path (0) | 2022.12.21 |
[BOJ 26552 // C++] Zero (0) | 2022.12.21 |
[BOJ 26535 // C++] Chicken Pen (0) | 2022.12.21 |
[BOJ 10187 // C++] Golden (0) | 2022.12.21 |