백준 1475 방번호

CJB_ny·2023년 1월 6일
0

백준

목록 보기
42/104
post-thumbnail

방 번호

처음에 어떻게 할지 생각하다가

counting star 생각해서 바로 갯수부터셈.

6이랑 9는 6번인덱스에 밀어넣고 %2했을 때 홀수 인지 짝수인지 비교부터함.

1이상의 홀수라면은 셋트수를 늘려야하니까

그리고 필요한 셋트수는 중복된 값이 가장큰 수대로 셋트수가 어쨋든 늘어나야한다.

#include <iostream>
#include <cstring>
using namespace std;
#define endl "\n"

int n, arr[10];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n;
	
	while (n != 0)
	{
		if (n % 10 == 6) ++arr[6];
		else if (n % 10 == 9) ++arr[6];
		else ++arr[n % 10];

		n = int(n / 10);
	}
	
	int Max = 0;
	for (int i = 0; i < 10; ++i)
	{
		if (i == 6)
		{
			if (arr[i] % 2 == 1) Max = max(Max, (arr[i] / 2) + 1);
			else Max = max(Max, (arr[i] / 2));
		}
		else Max = max(Max, arr[i]);
	}

	cout << Max << endl;

	return 0;
}
profile
https://cjbworld.tistory.com/ <- 이사중

0개의 댓글