-
Notifications
You must be signed in to change notification settings - Fork 0
/
2 - Conversor Decimal para Romano.cs
53 lines (47 loc) · 1.4 KB
/
2 - Conversor Decimal para Romano.cs
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
/*
Romanjs [Ou na linguagem que bem enteder]
Crie um conversor de números decimais para algarismos romanos
Ex:
Ao preencher:
1
Deve exibir:
I
---
2
Deve exibir:
II
---
3
Deve exibir:
III
---
4
Deve exibir:
IV
*/
namespace Logikoz.Desafios
{
class Decimal2Roman
{
public static string ToRoman(uint value)
{
(string, uint) a = (string.Empty, value);
while (a.Item2 != 0)
{
if (a.Item2 >= 1000) a = (a.Item1 += "M", a.Item2 -= 1000);
else if (a.Item2 >= 900) a = (a.Item1 += "CM", a.Item2 -= 900);
else if (a.Item2 >= 500) a = (a.Item1 += "D", a.Item2 -= 500);
else if (a.Item2 >= 100) a = (a.Item1 += "C", a.Item2 -= 100);
else if (a.Item2 >= 90) a = (a.Item1 += "XC", a.Item2 -= 90);
else if (a.Item2 >= 50) a = (a.Item1 += "L", a.Item2 -= 50);
else if (a.Item2 >= 40) a = (a.Item1 += "XL", a.Item2 -= 40);
else if (a.Item2 >= 10) a = (a.Item1 += "X", a.Item2 -= 10);
else if (a.Item2 >= 9) a = (a.Item1 += "IX", a.Item2 -= 9);
else if (a.Item2 >= 5) a = (a.Item1 += "V", a.Item2 -= 5);
else if (a.Item2 >= 4) a = (a.Item1 += "IV", a.Item2 -= 4);
else if (a.Item2 >= 1) a = (a.Item1 += "I", a.Item2 -= 1);
}
return a.Item1;
}
}
}