#Python code for 7225. Word To Number Problem code: WORDNUM
import re
c="teen";s="seven";e="eigh";n="nine";f="four";X="six";T="thir";y="ty"
U ={'zero':0,'one':1,'two':2,'three':3,f:4,'five':5,X:6,s:7,e+'t':8,n:9,'ten':10,'eleven':11,'twelve':12,T+c:13,f+c:14,'fif'+c:15,X+c:16,s+c:17,e+c:18,n+c:19,'twen'+y:20,T+y:30,'for'+y:40,'fif'+y:50,X+y:60,s+y:70,e+y:80,n+y:90}
M={'thousand':1000,'hundred':100}
def x(s):
a=re.split(r"[\s-]+",s)
n=g=0
for w in a:
x=U.get(w)
if x:
g+=x
x=M.get(w)
if x:n+=g*x;g=0
print n+g
for t in range(input()):x(raw_input())
import re
c="teen";s="seven";e="eigh";n="nine";f="four";X="six";T="thir";y="ty"
U ={'zero':0,'one':1,'two':2,'three':3,f:4,'five':5,X:6,s:7,e+'t':8,n:9,'ten':10,'eleven':11,'twelve':12,T+c:13,f+c:14,'fif'+c:15,X+c:16,s+c:17,e+c:18,n+c:19,'twen'+y:20,T+y:30,'for'+y:40,'fif'+y:50,X+y:60,s+y:70,e+y:80,n+y:90}
M={'thousand':1000,'hundred':100}
def x(s):
a=re.split(r"[\s-]+",s)
n=g=0
for w in a:
x=U.get(w)
if x:
g+=x
x=M.get(w)
if x:n+=g*x;g=0
print n+g
for t in range(input()):x(raw_input())
No comments:
Post a Comment