MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / int_to_roman

Function int_to_roman

12-integer-to-roman.rs:1–13  ·  view source on GitHub ↗
(num: i32)

Source from the content-addressed store, hash-verified

1pub fn int_to_roman(num: i32) -> String {
2 let mut num = num;
3 let values = vec![1000,900,500,400,100,90,50,40,10,9,5,4,1];
4 let reps = vec!["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"];
5 let mut ret = String::new();
6 for i in 0..13 {
7 while num >= values[i] {
8 num -= values[i];
9 ret.push_str(reps[i]);
10 }
11 }
12 ret.to_string()
13}
14
15fn main() {
16 let num = 1994;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected