반응형
문제
해설
코드
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char arr[101];
char arr1[101];
char arr2[101];
char arr3[101];
int cnt1, cnt2, cnt3;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int N;
int check[3] = { 0, };
cin >> N;
for (int i = 1; i <= N; i++) cin >> arr[i];
for (int i = 1; i <= N; i++) {
if (i % 3 == 1) arr1[i] = 'A';
else if (i % 3 == 2) arr1[i] = 'B';
else if (i % 3 == 0) arr1[i] = 'C';
if (i % 4 == 1 || i % 4 == 3) arr2[i] = 'B';
else if (i % 4 == 2) arr2[i] = 'A';
else if (i % 4 == 0) arr2[i] = 'C';
if (i % 6 == 1 || i % 6 == 2) arr3[i] = 'C';
else if (i % 6 == 3 || i % 6 == 4) arr3[i] = 'A';
else if (i % 6 == 5 || i % 6 == 0) arr3[i] = 'B';
}
for (int i = 1; i <= N; i++) {
if (arr[i] == arr1[i] && arr[i] != arr2[i] && arr[i] != arr3[i]) cnt1++;
else if (arr[i] == arr2[i] && arr[i] != arr1[i] && arr[i] != arr3[i]) cnt2++;
else if (arr[i] == arr3[i] && arr[i] != arr1[i] && arr[i] != arr2[i]) cnt3++;
else if (arr[i] == arr1[i] && arr[i] == arr2[i] && arr[i] != arr3[i]) cnt1++, cnt2++;
else if (arr[i] == arr1[i] && arr[i] == arr3[i] && arr[i] != arr2[i]) cnt1++, cnt3++;
else if (arr[i] == arr2[i] && arr[i] == arr3[i] && arr[i] != arr1[i]) cnt2++, cnt3++;
else if (arr[i] == arr1[i] && arr[i] == arr2[i] && arr[i] == arr3[i]) cnt1++, cnt2++, cnt3++;
}
if (cnt1 > cnt2 && cnt1 > cnt3)cout << cnt1 << '\n' << "Adrian";
else if (cnt2 > cnt1 && cnt2 > cnt3)cout << cnt2 << '\n' << "Bruno";
else if (cnt3 > cnt1 && cnt3 > cnt2)cout << cnt3 << '\n' << "Goran";
else if (cnt1 == cnt2 && cnt1 > cnt3)cout << cnt1 << '\n' << "Adrian" << '\n' << "Bruno";
else if (cnt1 == cnt3 && cnt1 > cnt2)cout << cnt1 << '\n' << "Adrian" << '\n' << "Goran";
else if (cnt2 == cnt3 && cnt2 > cnt1)cout << cnt2 << '\n' << "Bruno" << '\n' << "Goran";
else if (cnt1 == cnt2 && cnt1 == cnt3 && cnt2 == cnt3)cout << cnt1 << '\n' << "Adrian" << '\n' << "Bruno" << '\n' << "Goran";
return 0;
}
반응형
'Development > Algorithm' 카테고리의 다른 글
[BOJ] 2606. 바이러스 (0) | 2020.10.04 |
---|---|
[BOJ] 10809. 알파벳 찾기 (0) | 2020.10.03 |
[BOJ] 10448. 유레카 이론 (0) | 2020.10.02 |
[BOJ] 2231. 분해합 (0) | 2020.10.02 |
[BOJ] 2309. 일곱 난쟁이 (0) | 2020.09.30 |