-
Notifications
You must be signed in to change notification settings - Fork 0
/
u.nex
43 lines (43 loc) · 927 Bytes
/
u.nex
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
/[零一二三四五六七八九十百千]+/ { fmt.Print(zhToInt(txt())) }
/[٠-٩]/ {
// The above character class might show up right-to-left in a browser.
// The equivalent of 0 should be on the left, and the equivalent of 9 should
// be on the right.
//
// The Eastern Arabic numerals are ٠١٢٣٤٥٦٧٨٩.
fmt.Print([]int(txt())[0] - int('٠'))
}
//
package main
import "fmt"
func zhToInt(s string) int {
n := 0
prev := 0
f := func(m int) {
if 0 == prev { prev = 1 }
n += m * prev
prev = 0
}
for _, c := range s {
for m, v := range []int("一二三四五六七八九") {
if v == c {
prev = m+1
goto continue2
}
}
switch c {
case '零':
case '十': f(10)
case '百': f(100)
case '千': f(1000)
}
continue2:
}
n += prev
return n
}
func main() {
lex := NewLexer(os.Stdin)
txt := func() string { return lex.Text() }
NN_FUN(lex)
}