https://www.acmicpc.net/problem/11507
11507번: 카드셋트
예제1 : 12 12 11 13은 잃어버린 P카드 : 12개, K : 12개, H : 11개, T : 13라는 뜻이다. 예제2 : 같은 카드(H02)가 존재하므로 GRESKA을 출력하였다.
www.acmicpc.net
문제 해설
잃어버린 카드의 목록이 주어질 때,
카드의 모양을 구분하여 갖고 있는 카드의 수를 출력하는 문제다.
구현 문제에 가깝다고 생각한다.
#include <iostream>
#define fio cin.tie(0)->sync_with_stdio(0)
using namespace std;
#include <set>
int main(){
fio;
string S; cin >> S;
set<int> P, K, H, T;
bool dupl = false;
for(int i=0; i<S.size(); i+=3){
char C = S[i];
string tmp;
tmp += S[i+1];
tmp += S[i+2];
int XY = stoi(tmp);
//
if(C =='P'){
if(P.find(XY) != P.end()){
dupl = true;
break;
}else{
P.insert(XY);
}
}else if(C =='K'){
if(K.find(XY) != K.end()){
dupl = true;
break;
}else{
K.insert(XY);
}
}else if(C =='H'){
if(H.find(XY) != H.end()){
dupl = true;
break;
}else{
H.insert(XY);
}
}else{//T
if(T.find(XY) != T.end()){
dupl = true;
break;
}else{
T.insert(XY);
}
}
}
//
if(dupl){
cout <<"GRESKA";
}else{
cout << 13 - P.size()<<' ';
cout << 13 - K.size()<<' ';
cout << 13 - H.size()<<' ';
cout << 13 - T.size()<<' ';
}
return 0;
}
'알고리즘 > 백준' 카테고리의 다른 글
백준 12034 김인천씨의 식료품가게 (Large) (0) | 2021.12.27 |
---|---|
백준 11645 I’ve Been Everywhere, Man (0) | 2021.12.27 |
백준 11346 Cornell Party - Retry (0) | 2021.12.27 |
백준 11235 Polling (0) | 2021.12.27 |
백준 11116 교통량 (0) | 2021.12.27 |