PS/BOJ
[백준] 1475. 방 번호(c++)
backend 개발자 지망생
2025. 1. 15. 14:27
https://www.acmicpc.net/problem/1475
6과 9라는 분기 처리와 배열 인덱스에 추가하는 문제였다.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <limits.h>
#include <queue>
#include <set>
#include <math.h>
#include <stack>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int arr[10] = { 0 };
int ans = 0;
while (n > 0) {
if (n % 10 == 6 || n % 10 == 9) {
arr[6]++;
}
else {
arr[n % 10]++;
}
n /= 10;
}
for (int i = 0; i < 9; i++) {
if (i == 6) {
if (arr[6] % 2 == 0)
ans = max(ans, arr[6] / 2);
else
ans = max(ans, arr[6] / 2 + 1);
}
else {
ans = max(ans, arr[i]);
}
}
cout << ans;
return 0;
}