문제 : https://www.acmicpc.net/problem/8896
[알고리즘풀이]
단순 구현 문제입니다.
각 라운드마다 가위, 바위, 보를 카운팅 한 후 각 경우마다 패배자를 Check해서 1명이 남을 때까지 라운드를 진행합니다.
#include<iostream>
#include<string>
using namespace std;
string list[11];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool check[11] = {}; // i번째 선수가 졌으면 check[i] = true;
bool flag = false;
for (int i = 1; i <= n; i++)
cin >> list[i];
for (int i = 0; i < list[1].length(); i++) {
bool RPS[3] = {}; // R P S 나온걸체크
for (int j = 1; j <= n; j++) {
if (check[j] == true) // 이미 기존에 진사람
continue;
if (list[j][i] == 'R')
RPS[0] = true;
if (list[j][i] == 'P')
RPS[1] = true;
if (list[j][i] == 'S')
RPS[2] = true;
}
// R P S 가 다 나온 경우.
if (RPS[0] && RPS[1] && RPS[2])
continue;
// R P 가 나온 경우
if (RPS[0] && RPS[1] && !RPS[2]) {
for (int j = 1; j <= n; j++)
if (check[j] == false && list[j][i] == 'R')
check[j] = true;
}
// R S 가 나온 경우
if (RPS[0] && !RPS[1] && RPS[2]) {
for (int j = 1; j <= n; j++)
if (check[j] ==false && list[j][i] == 'S')
check[j] = true;
}
// P S 가 나온 경우
if (!RPS[0] && RPS[1] && RPS[2]) {
for (int j = 1; j <= n; j++)
if (check[j] == false && list[j][i] == 'P')
check[j] = true;
}
int count = 0, index = 0;
for (int j = 1; j <= n; j++) {
if (check[j] == false) {
count++;
index = j;
}
}
if (count == 1){
cout << index << '\n';
flag = true;
break;
}
}
if (!flag)
cout << 0 << '\n';
}
}
'Problem Solving > ICPC' 카테고리의 다른 글
[ICPC][BOJ] 8912 - Sales (0) | 2019.09.23 |
---|---|
[ICPC][BOJ] 9093 - Word Reversal (0) | 2019.09.23 |
[ACM-ICPC][BOJ] 10251 - Driving License (0) | 2019.08.27 |
[ACM-ICPC][BOJ] 9019 - DSLR (0) | 2019.08.16 |
[ACM-ICPC][BOJ] 3758 - KCPC (0) | 2019.08.09 |