https://www.acmicpc.net/problem/2966
문제 접근법 :
찍는 방법을 시뮬레이션하듯 그대로 구현하면 되기때문에 어렵지 않은문제입니다.
이것에대한 풀이는 굉장히 많을거라 코드만 올려드리겠습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <algorithm>
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int n;
string s;
void input() {
cin >> n;
cin >> s;
}
void solve() {
string s1[3] = { "ABC","BABC","CCAABB" };
string res[3] = { "Adrian","Bruno","Goran" };
vector<string> v;
for (int i = 0; i < 3; i++) {
string temp = s1[i];
while (s1[i].size() <= 100)
s1[i] += temp;
}
int maxcnt = 0;
for (int i = 0; i < 3; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (s1[i][j] == s[j])
cnt++;
}
if (maxcnt < cnt) {
v.clear();
v.push_back(res[i]);
maxcnt = cnt;
}
else if (maxcnt == cnt) {
v.push_back(res[i]);
}
}
sort(v.begin(), v.end());
cout << maxcnt << "\n";
for (auto it : v)
cout << it << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
solve();
}
|
cs |
댓글은 언제나 환영입니다.
'백준' 카테고리의 다른 글
백준 1080 행렬 (0) | 2021.06.17 |
---|---|
백준 16958 텔레포트 (0) | 2021.06.17 |
백준 2997 네 번째 수 (0) | 2021.06.17 |
백준 11003 최솟값 찾기 (0) | 2021.05.27 |
백준 20166 문자열 지옥에 빠진 호석 (0) | 2021.05.25 |