[백준] 1475번 방 번호 / C++

#문제

백준 1475번 방 번호

#풀이

#include <iostream>
#include <string>

using namespace std;

int number_set[10] = { 0 };

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);

	string n;
	cin >> n;

	for (int i = 0; i < n.size(); ++i)
	{
		int x = n[i] - '0';
		number_set[x]++;
	}

	int six_nine = (number_set[6] + number_set[9] + 1) / 2;
	number_set[6] = number_set[9] = six_nine;

	int cnt = 0;

	for (int i = 0; i < 10; ++i)
	{
		if (number_set[i] > cnt)
		{
			cnt = number_set[i];
		}
	}

	cout << cnt;

	return 0;
}

#정리

방 번호 N을 장식하는데, 0-9까지 들어있는 숫자 세트를 몇 개를 써야 하는 지를 계산하는 프로그램 코드를 작성하는 문제. 숫자 0-9에서 가장 많이 중복되는 숫자의 개수를 출력하면 되는 간단한 문제. 하지만 6과 9는 치환이 가능하다는 기믹이 있다. 6과 9를 각각 6의 개수와 9의 개수를 더 해 항상 반올림이 되도록 +1을 한 후 2로 나눠준 수를 대입하고, 예상대로 숫자를 출력하면 해결.




    Enjoy Reading This Article?

    Here are some more articles you might like to read next:

  • [백준] 1269번 대칭 차집합 / C++
  • [백준] 2003번 수들의 합 2 / C++
  • [백준] 1018번 체스판 다시 칠하기 / C++
  • [백준] 2563번 색종이 / C++
  • [백준] 10773번 제로 / C++