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 |
数据躲过了,why waimport java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sca = new Scanner(System.in); ArrayList<Integer> al = new ArrayList<Integer>(); ArrayList<Integer> sj = new ArrayList<Integer>(); HashMap<String, Integer> hm = new HashMap<String, Integer>(); while (true) { String arr = sca.next(); if (arr.equals("END_OF_FIRST_PART")) { break; } else {//(C(H)3)4 hm.put(arr, sca.nextInt()); } } while (true) { String ai = sca.next(); //System.out.println(ai.length()); if (ai.equals("0")) { break; } else { for (int j = 0; j < ai.length(); j++) { int k = ai.charAt(j); if (k == 41) { int index = 1; String z = ""; if (j + 1 < ai.length()) { if (ai.charAt(j + 1) >= 48 && ai.charAt(j + 1) <= 57) { z = (char) (int) ai.charAt(j + 1) + ""; if (j + 2 < ai.length()) { if (ai.charAt(j + 2) >= 48 && ai.charAt(j + 2) <= 57) { z = z+(char) (int) ai.charAt(j + 2) + ""; j++;//System.out.println("NICE"+j); } } } index = Integer.parseInt(z); j++; } for (int n = al.size() - 1; n >= 0; n--) { if (al.get(n) == 40) { al.remove(n); break; } else { sj.add(0, al.get(n)); al.remove(n); } } for (int n = 0; n < index; n++) { al.addAll(sj); } sj.clear(); } else { al.add(k); } } // for (int i = 0; i < al.size(); i++) { // System.out.print((char) (int) al.get(i)); // } //System.out.println(); String over = ""; int sum = 0; boolean judge = true; for (int i = 0; i < al.size(); i++) { over=over+(char)(int)al.get(i); if(i+1<al.size()){ if(al.get(i+1)>=48&&al.get(i+1)<=57){ String z=(char)(int)al.get(i+1)+""; if(hm.get(over)==null){ judge=false; break; }else{ sum=sum+hm.get(over)*Integer.parseInt(z); over="";i++; } }else if(al.get(i+1)>=65&&al.get(i+1)<=90){ if(hm.get(over)==null){ judge=false; break; }else{ sum=sum+hm.get(over); over=""; } } else if(al.get(i+1)>=97&&al.get(i+1)<=122){ over=over+(char)(int)al.get(i+1); if(i+2<al.size()){ if(al.get(i+2)>=48&&al.get(i+2)<=57){ String z=(char)(int)al.get(i+2)+""; if(hm.get(over)==null){ judge=false; break; }else{ sum=sum+hm.get(over)*Integer.parseInt(z); over="";i++; } }else{ if(hm.get(over)==null){ judge=false; break; }else{ sum=sum+hm.get(over); over=""; } } }else{ if(hm.get(over)==null){ judge=false; break; }else{ sum=sum+hm.get(over); over=""; } } i++; } }else{ if(hm.get(over)==null){ judge=false; break; }else{ sum=sum+hm.get(over); over=""; } } // System.out.println(sum); }// System.out.println(sum); if (judge) { System.out.println(sum); } else { System.out.println("UNKNOWN"); } al.clear(); sj.clear(); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator