Topic 1010:a + B

Source: Internet
Author: User

Title Description:
Read in two positive integers a and B less than 100, 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 both A and B are at the end of 0 o'clock input, the corresponding result is not output.
Output:
Output 1 rows for each test case, which is the value of a+b.
Sample input:
One + =three four + five six =zero seven + eight nine =zero + zero =
Sample output:
39096
1 Importjava.util.Hashtable;2 ImportJava.util.Scanner;3  4  Public classmain{5      Public Static voidMain (String[]args) {6Scanner in=NewScanner (system.in);7Hashtable<string,integer> ht=NewHashtable ();8 inithashtable (HT);9          while(In.hasnext ()) {TenString input=in.nextline (); OneString[] T=input.split (""); A             intlen=t.length; -             intCout=0; -string[]num=NewString[2]; theNum[0]= ""; -Num[1]= "";//Be sure to initialize to an empty string, otherwise add a number, such as 1, will become null1; -              for(inti=0;i<len;i++){ -                 if(T[i].equals ("+")){ +cout++; -                     Continue; +                 } A                 Else if(T[i].equals ("=")){ at                     Continue; -                 } -                 intA=Ht.get (T[i]); -num[cout]=num[cout]+A; -             } -             intX=integer.parseint (num[0]); in             intY=integer.parseint (num[1]); -             if(x==0&&y==0){ to                  Break; +             } -System.out.println (x+y);  the         } *     } $      Panax Notoginseng      Public Static voidInitHashTable (hashtable<string,integer>HT) { -Ht.put ("zero", 0); theHt.put ("One", 1); +Ht.put ("Both", 2); AHt.put ("Three", 3); theHt.put ("Four", 4); +Ht.put ("Five", 5); -Ht.put ("Six", 6); $Ht.put ("Seven", 7); $Ht.put ("Eight", 8); -Ht.put ("Nine", 9); -Ht.put ("Tene", 10); the     } - }Wuyi /************************************************************** the problem:1010 - user:0000h Wu Language:java - result:accepted About time:80 Ms $ memory:15548 KB - ****************************************************************/

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.