March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -13,7 +13,7 @@ void roman(char *s, unsigned int n)
|
|||
{
|
||||
if (n == 0)
|
||||
{
|
||||
fputs(stderr, "Roman numeral for zero requested.");
|
||||
fputs("Roman numeral for zero requested.", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
TOROMAN(n)
|
||||
;return empty string if input parameter 'n' is not in 1-3999
|
||||
Quit:(n'?1.4N)!(n'<4000)!'n ""
|
||||
New r Set r=""
|
||||
New p Set p=$Length(n)
|
||||
New j,x
|
||||
For j=1:1:p Do
|
||||
. Set x=$Piece("~I~II~III~IV~V~VI~VII~VIII~IX","~",$Extract(n,j)+1)
|
||||
. Set x=$Translate(x,"IVX",$Piece("IVX~XLC~CDM~M","~",p-j+1))
|
||||
. Set r=r_x
|
||||
Quit r
|
||||
37
Task/Roman-numerals-Encode/Rust/roman-numerals-encode.rust
Normal file
37
Task/Roman-numerals-Encode/Rust/roman-numerals-encode.rust
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
struct RomanNumeral {
|
||||
symbol: &'static str,
|
||||
value: uint
|
||||
}
|
||||
|
||||
static NUMERALS: [RomanNumeral, ..13] = [
|
||||
RomanNumeral {symbol: "M", value: 1000},
|
||||
RomanNumeral {symbol: "CM", value: 900},
|
||||
RomanNumeral {symbol: "D", value: 500},
|
||||
RomanNumeral {symbol: "CD", value: 400},
|
||||
RomanNumeral {symbol: "C", value: 100},
|
||||
RomanNumeral {symbol: "XC", value: 90},
|
||||
RomanNumeral {symbol: "L", value: 50},
|
||||
RomanNumeral {symbol: "XL", value: 40},
|
||||
RomanNumeral {symbol: "X", value: 10},
|
||||
RomanNumeral {symbol: "IX", value: 9},
|
||||
RomanNumeral {symbol: "V", value: 5},
|
||||
RomanNumeral {symbol: "IV", value: 4},
|
||||
RomanNumeral {symbol: "I", value: 1}
|
||||
];
|
||||
|
||||
fn to_roman(num: uint) -> ~str {
|
||||
for numeral in NUMERALS.iter() {
|
||||
if num >= numeral.value {
|
||||
return numeral.symbol + to_roman(num - numeral.value);
|
||||
}
|
||||
}
|
||||
|
||||
return ~"";
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let nums = [2014, 1999, 25, 1666, 3888];
|
||||
for n in nums.iter() {
|
||||
println!("{:u} = {:s}", *n, to_roman(*n));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue