Topic 1010:a + B

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.