-
-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathInteger_To_Roman.dart
More file actions
67 lines (60 loc) · 846 Bytes
/
Integer_To_Roman.dart
File metadata and controls
67 lines (60 loc) · 846 Bytes
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
///Author: Shawn
///Email: [email protected]
/*
*
* Concerting Integers into Roman Numerals
*
*/
List<int> ArabianRomanNumbers = [
1000,
900,
500,
400,
100,
90,
50,
40,
10,
9,
5,
4,
1,
];
List<String> RomanNumbers = [
"M",
"CM",
"D",
"CD",
"C",
"XC",
"L",
"XL",
"X",
"IX",
"V",
"IV",
"I",
];
List<String> integer_to_roman(int num) {
if (num < 0) {
return [];
}
List<String> result = [];
for (int i = 0; i < ArabianRomanNumbers.length; i++) {
int times = num ~/ ArabianRomanNumbers[i];
for (int j = 0; j < times; j++) {
print(RomanNumbers[i]);
}
num -= times * ArabianRomanNumbers[i];
}
return result;
}
int main() {
/* IV */
integer_to_roman(4);
/* II */
integer_to_roman(2);
/* M */
integer_to_roman(1000);
return 0;
}