-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.RomanToInt.go
46 lines (36 loc) · 824 Bytes
/
1.RomanToInt.go
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
/*
* Name : sk shahriar ahmed raka
* Email : skshahriarahmedraka@gmail.com
* Telegram : https://www.t.me/shahriarraka
* Github : https://github.com/skshahriarahmedraka
*/
package main
import "fmt"
func RomanToInteger(roman string)uint64{
var ro =map[string]uint64{"I":1,"V":5,"X":10,"L":50,
"C":100,"D":500,"M":1000} //,"_V":5000,"_X":10000,"_L":50000, "_C":100000,"_D":500000,"_M":1000000
var (
t uint64
slen uint64
h uint64
)
slen =uint64(len(roman))
for ;h<slen;h++ {
if (h+1 <slen) && ro[string(roman[h])] < ro[string(roman[h+1])] {
t -= ro[string(roman[h])]
}else {
t += ro[string(roman[h])]
}
}
return t
}
func main(){
fmt.Printf("give a roman number (like VIII) : ")
var (
s string
n uint64
)
fmt.Scanln(&s)
n=RomanToInteger(s)
fmt.Println("integer value : ",n)
}