This commit is contained in:
VicRen
2020-12-02 08:51:48 +08:00
parent c93930c737
commit 410825768e
2 changed files with 79 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package main
var r2d = map[uint8]int{
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000,
}
func main() {
}
func RomaToDigit(s string) int {
l := len(s)
ret := 0
for i := 0; i < l; i++ {
c := r2d[s[i]]
ret += c
if i >= l-1 {
break
}
cn := r2d[s[i+1]]
if cn > c {
ret -= 2 * c
}
}
return ret
}