Website Summary Files Commits Branches @commit @diff @stats
path: root / Week06 / Exercise03.cpp
blob: e85d358b68e30975c8d6f52d8ab9b8e3bb07efe6 (plain) (blame)
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
35
36
37
38
39
40
#include <iostream>

int main() {
	unsigned int number;
	std::cin >> number;

	const unsigned int DIGITS = 10;
	unsigned char counts[DIGITS] = { 0 };

	unsigned int temp_number = number, number_length = 0;
	while (temp_number > 0) {
		counts[temp_number % 10]++;
		temp_number /= 10;
		number_length++;
	}

	unsigned int most_common = 0;
	for (unsigned int digit = 1; digit < DIGITS; digit++) {
		if (counts[digit] >= counts[most_common])
			most_common = digit;
	}

	unsigned int shifter = 1;
	for (unsigned int i = 0; i < number_length - 1; i++) {
		shifter *= 10;
	}

	while (shifter > 0) {
		if ((number / shifter) % 10 == most_common)
			temp_number *= 10;
		else
			temp_number = temp_number * 10 + (number / shifter) % 10;

		shifter /= 10;
	}

	std::cout << temp_number << std::endl;

	return 0;
}