标签:
one + two = three four + five six = zero seven + eight nine = zero + zero =
3 90 96
1 import java.util.Hashtable; 2 import java.util.Scanner; 3 4 public class Main{ 5 public static void main(String[]args){ 6 Scanner in=new Scanner(System.in); 7 Hashtable<String,Integer> ht=new Hashtable(); 8 initHashtable(ht); 9 while(in.hasNext()){ 10 String input=in.nextLine(); 11 String[] t=input.split(" "); 12 int len=t.length; 13 int cout=0; 14 String[]num=new String[2]; 15 num[0]=""; 16 num[1]="";//一定要初始化为空串,不然加上一个数字,比如1,就会变成null1; 17 for(int i=0;i<len;i++){ 18 if(t[i].equals("+")){ 19 cout++; 20 continue; 21 } 22 else if(t[i].equals("=")){ 23 continue; 24 } 25 int a=ht.get(t[i]); 26 num[cout]=num[cout]+a; 27 } 28 int x=Integer.parseInt(num[0]); 29 int y=Integer.parseInt(num[1]); 30 if(x==0&&y==0){ 31 break; 32 } 33 System.out.println(x+y); 34 } 35 } 36 37 public static void initHashtable(Hashtable<String,Integer> ht){ 38 ht.put("zero",0); 39 ht.put("one",1); 40 ht.put("two",2); 41 ht.put("three",3); 42 ht.put("four",4); 43 ht.put("five",5); 44 ht.put("six",6); 45 ht.put("seven",7); 46 ht.put("eight",8); 47 ht.put("nine",9); 48 ht.put("tene",10); 49 } 50 } 51 /************************************************************** 52 Problem: 1010 53 User: 0000H 54 Language: Java 55 Result: Accepted 56 Time:80 ms 57 Memory:15548 kb 58 ****************************************************************/
标签:
原文地址:http://www.cnblogs.com/qq1029579233/p/4418739.html