Nine One, three four five six seven eight
topic 1010:A + B
Time limit:1 seconds memory limit:
Title Description:
Read two positive integers a and B less than three, calculate a+b.
It is important to note that each digit of a and B is given by the corresponding English word .
Input:
The test input contains several test cases , one row for each test case , the format "A + B =", and two adjacent strings with a space interval . when A and the B also for 0 when input ends , the corresponding results do not output .
Output:
Output 1 rows for each test case , which is The value of a+b .
Sample input:
One + one =
Three four + five six =
Zero Seven + eight nine =
Zero + zero =
Sample output:
3
90
96
/**************************************************************
problem:1010
User:watchfree
Language:java
result:accepted
Time:90 ms
memory:15564 kb
There are bugs, AC ,
****************************************************************/
ImportJava.util.Scanner; Public classMain {Staticstring Change (String str) {if(Str.equals ("one"))return"1"; if(Str.equals ("both"))return"2"; if(Str.equals ("three"))return"3"; if(Str.equals ("four"))return"4"; if(Str.equals ("Five"))return"5"; if(Str.equals ("Six"))return"6"; if(Str.equals ("Seven"))return"7"; if(Str.equals ("eight"))return"8"; if(Str.equals ("Nine"))return"9"; if(Str.equals ("Zero"))return"0"; Else return""; } Static intchangenum (String str) {returnInteger.parseint (Str.trim ()); } Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in); while(Sc.hasnext ()) {String str=Sc.nextline (); String num[]=str.split ("\\+"); String num1[]=num[0].split (""); String tmp1= "", tmp2= ""; String num2[]=num[1].split (""); for(inti=0;i<num1.length;i++) {TMP1+=Change (Num1[i]); } for(inti=0;i<num2.length;i++) {TMP2+=Change (Num2[i]); } if(Changenum (TMP1) +changenum (TMP2) ==0) Break; System.out.println (Changenum (TMP1)+Changenum (TMP2)); } sc.close (); } }
Topic 1010:a + B