본문 바로가기
PS/BOJ

[백준] 1475. 방 번호(c++)

by backend 개발자 지망생 2025. 1. 15.

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;
}

'PS > BOJ' 카테고리의 다른 글

[백준] 10807. 개수 세기(c++)  (0) 2025.01.19
[백준] 3273. 두 수의 합(c++)  (0) 2025.01.16
[백준] 2577. 숫자의 개수(c++)  (0) 2025.01.15
[백준] 10808. 알파벳 개수(c++)  (0) 2025.01.13
[백준] 23842. 성냥개비(c++)  (0) 2024.12.27