|
|
@ -1,3 +1,41 @@ |
|
|
|
#![allow(unused)]
|
|
|
|
fn main() {
|
|
|
|
println!("Hello, world!");
|
|
|
|
|
|
|
|
let args = vec![
|
|
|
|
182,
|
|
|
|
1990,
|
|
|
|
1875,
|
|
|
|
];
|
|
|
|
|
|
|
|
println!();
|
|
|
|
|
|
|
|
for arg in args {
|
|
|
|
println!("{:4} | {:?}", arg, func(arg));
|
|
|
|
};
|
|
|
|
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func(num: i32) -> String {
|
|
|
|
let mut out = vec![];
|
|
|
|
let mut stack = vec![
|
|
|
|
(1, "I"), (4, "IV"), (5, "V"), (9, "IX"),
|
|
|
|
(10, "X"), (40, "XL"), (50, "L"),
|
|
|
|
(90, "XC"), (100, "C"), (400, "CD"),
|
|
|
|
(500, "D"), (900, "CM"), (1000, "M"),
|
|
|
|
];
|
|
|
|
|
|
|
|
let mut num = num;
|
|
|
|
|
|
|
|
while let Some(div) = stack.pop() {
|
|
|
|
while num/div.0 > 0 {
|
|
|
|
out.push(div.1);
|
|
|
|
num -= div.0;
|
|
|
|
}
|
|
|
|
if num == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out.join("")
|
|
|
|
}
|