Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
其实这题最大范围都在那了,不过输入结束为空行import java.util.*; public class Main{ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sca = new Scanner(System.in); HashMap<String, Integer> hm = new HashMap<String, Integer>(); hm.put("zero", 0); hm.put("one", 1); hm.put("two", 2); hm.put("three", 3); hm.put("four", 4); hm.put("five", 5); hm.put("six", 6); hm.put("seven", 7); hm.put("eight", 8); hm.put("nine", 9); hm.put("ten", 10); hm.put("eleven", 11); hm.put("twelve", 12); hm.put("thirteen", 13); hm.put("fourteen", 14); hm.put("fifteen", 15); hm.put("sixteen", 16); hm.put("seventeen", 17); hm.put("eighteen", 18); hm.put("nineteen", 19); hm.put("twenty", 20); hm.put("thirty", 30); hm.put("forty", 40); hm.put("fifty", 50); hm.put("sixty", 60); hm.put("seventy", 70); hm.put("eighty", 80); hm.put("ninety", 90); while(sca.hasNextLine()){ String ai=sca.nextLine(); if(ai.equals("")){ break; } int i=0;int sum=0;boolean judge=true; String arr[]=ai.split(" "); if(arr[0].equals("negative")){ i=1;judge=false; } int temp=0;int temp1=0; while(i<arr.length){ if(hm.get(arr[i])!=null){ sum=sum+hm.get(arr[i]); }else if(arr[i].equals("hundred")){ sum=sum*100; }else if(arr[i].equals("thousand")){ sum=sum*1000;temp1=sum;sum=0; }else{ sum=sum*1000000;temp=sum;sum=0; } i++; }if(judge){System.out.println(sum+temp+temp1);} else{ System.out.println("-"+(sum+temp+temp1)); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator