💡 구현
Memory 2416KB Time 0ms Code Length 509B
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
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
string input_data;
int mem_list[100001] = { 0 };
void init() {
cin >> input_data;
}
void solve() {
for (int i = 0; i < input_data.size(); i++) {
int a = input_data[i] - '0';
mem_list[a]++;
}
int max = 0;
for (int i = 0; i < 9; i++) {
int now = mem_list[i];
if (i == 6) {
now += mem_list[9];
now = ceil((double)now / 2);
}
if (max < now) {
max = now;
}
}
cout << max;
}
int main() {
init();
solve();
}
이 코드는 입력된 숫자를 분석하여 가장 많이 등장하는 숫자의 개수를 찾아 출력하는 프로그램이다. init 함수에서는 사용자로부터 숫자를 입력받고, solve 함수에서는 입력된 숫자를 하나씩 확인하면서 각 숫자의 등장 횟수를 기록한다. 그 후, 6과 9는 묶어서 처리하고, 모든 숫자에 대해 등장 횟수를 비교하여 가장 많이 등장한 숫자의 개수를 찾는다. 이후 이 값을 출력한다.