-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path2.2.1 - Preface Numbering.cpp
109 lines (99 loc) · 2.29 KB
/
2.2.1 - Preface Numbering.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
ID: nathan.18
TASK: preface
LANG: C++
*/
#include <iostream>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cassert>
using namespace std;
#define INF 1000000000
#define LL_INF 4500000000000000000
#define LSOne(S) (S & (-S))
#define EPS 1e-9
#define A first
#define B second
#define mp make_pair
#define PI acos(-1.0)
#define ll long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
map<char, int> counter;
void run(int num) {
if (num >= 1000) {
counter['M'] += num/1000;
run(num%1000);
} else if (num >= 500) {
if (num < 900) {
counter['D'] += num/500;
run(num%500);
} else {
counter['C']++;
counter['M']++;
run(num%100);
}
} else if (num >= 100) {
if (num < 400) {
counter['C'] += num/100;
run(num%100);
} else {
counter['C']++; counter['D']++;
run(num%100);
}
} else if (num >= 50) {
if (num < 90) {
counter['L'] += num/50;
run(num%50);
} else {
counter['X']++; counter['C']++;
run(num%10);
}
} else if (num >= 10) {
if (num < 40) {
counter['X'] += num/10;
run(num%10);
} else {
counter['X']++; counter['L']++;
run(num%10);
}
} else if (num >= 5) {
if (num < 9) {
counter['V'] += num/5;
run(num%5);
} else {
counter['I']++; counter['X']++;
}
} else if (num >= 1) {
if (num < 4) {
counter['I'] += num;
} else {
counter['I']++; counter['V']++;
}
}
}
int main() {
freopen("preface.in", "r", stdin);
freopen("preface.out", "w", stdout);
int n; cin >> n;
char chars[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
for (char c : chars) counter.insert(mp(c, 0));
for (int i = 1; i <= n; i++) {
run(i);
}
for (char c : chars) if (counter[c] != 0) cout << c << " " << counter[c] << endl;
return 0;
}