program i; const digits:array[0..19] of string[32]= ('zero','one','two','three','four','five','six', 'seven','eight','nine','ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen','seventeen','eighteen', 'nineteen'); const tens:array[2..9] of string[32]= ('twenty','thirty','forty','fifty','sixty','seventy', 'eighty','ninety'); jumps:array[1..3]of string[32]= ('hundred','thousand','million'); var S,OneWord,ValueStr:string[255]; K,I,J,Len,Space:Integer; Result:string[255]; Match:Boolean; Value,Gap,Pos,ResVal:Integer; Hun, Mil, Tho: Boolean; begin while True do begin ReadLn(S); Len:=Length(S); if Len=0 then Break; Result:=''; Gap:=0; Pos:=0; ResVal:=0; Hun:= False; Tho:= False; Mil:= False; {gap je kolonka ve ktery sme 0..2,pos je pozice v kolonce 0..2} K:=Len; while K>0 do begin Space:=0; {hledam mezeru} for J:=K downto 1 do if S[J]=' ' then begin Space:=J; Break; end; if Space=0 then begin OneWord:=Copy(S,1,K); K:=0; end else begin OneWord:=Copy(S,Space+1,K-Space+1); K:=Space-1; end; OneWord:=Trim(OneWord); WriteLn('OneWord = ',OneWord); Match:=False; if Length(OneWord)<>0 then begin for I:=0 to 19 do if OneWord=digits[I] then begin Value:=I; Match:=True; end; if not Match then for I:=2 to 9 do if OneWord=tens[I] then begin Value:=I*10; Match:=True; end; if not Match then for I:=1 to 3 do if OneWord=jumps[I]then begin Match:=True; case I of 1:Value:=100; 2:Value:=1000; 3:Value:=1000000; end; end; if not Match then if OneWord='negative' then begin Match:=True; Value:=-1; end; WriteLN('Value = ',Value) ; case Value of -1:ResVal:= - ResVal;{ult:='-'+Result;} 100: begin Hun:= True; end; {if Pos=0 then begin Result:='00'+Result; Pos:=2; end else if Pos=1 then begin Result:='0'+Result; Pos:=2; end; } 1000: begin Hun:= False; Tho:= True; end; {begin if Pos=0 then Result:='000'+Result else if Pos=1 then Result:='00'+Result else if Pos=2 then Result:='0'+Result; Pos:=0; Inc(Gap); end; } 1000000: begin Hun:= False; Tho:= False; Mil:= True; end; {begin if Gap=1 then begin if Pos=0 then Result:='000000'+Result else if Pos=1 then Result:='00000'+Result else if Pos=2 then Result:='0000'+Result; end else if Gap=2 then begin if Pos=0 then Result:='000'+Result else if Pos=1 then Result:='00'+Result else if Pos=2 then Result:='0'+Result; end; Gap:=2; end;} else begin if Hun then Value:= Value * 100; if Tho then Value:= Value * 1000; if Mil then Value:= Value * 1000000; ResVal:= ResVal + Value; end; { if (Value>10) and (Pos=2) then Value:=Value div 10; Str(Value,ValueStr); Result:=ValueStr+Result; if Value<10 then begin Pos:=(Pos+1) mod 3; if Pos=0 then Inc(Gap); end else begin if Pos<>0 then Inc(Gap); Pos:=(Pos+2) mod 3; end;} end; end; end; WriteLn(ResVal); end; end.