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 |
JAVA写的,为什么老WA啊?是内存开得不够?import java.io.*; import java.util.*; public class acm1002 { public static String Convert(String str) { String res=""; for(int i=0;i<str.length();i++) { if(str.charAt(i)>='0' && str.charAt(i)<='9') { res+=str.charAt(i); } else { if(str.charAt(i)=='A' || str.charAt(i)=='B' || str.charAt(i)=='C') res+='2'; else if(str.charAt(i)=='D' || str.charAt(i)=='E' || str.charAt(i)=='F') res+='3'; else if(str.charAt(i)=='G' || str.charAt(i)=='H' || str.charAt(i)=='I') res+='4'; else if(str.charAt(i)=='J' || str.charAt(i)=='K' || str.charAt(i)=='L') res+='5'; else if(str.charAt(i)=='M' || str.charAt(i)=='N' || str.charAt(i)=='O') res+='6'; else if(str.charAt(i)=='P' || str.charAt(i)=='R' || str.charAt(i)=='S') res+='7'; else if(str.charAt(i)=='T' || str.charAt(i)=='U' || str.charAt(i)=='V') res+='8'; else if(str.charAt(i)=='W' || str.charAt(i)=='X' || str.charAt(i)=='Y') res+='9'; } } return res.substring(0,3)+"-"+res.substring(3,7); } public static void main(String[] args) throws IOException{ Map<String,Integer> set = new HashMap<String,Integer>(); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); int num = Integer.parseInt(stdIn.readLine()); for(int i=1;i<=num;i++) { String res = stdIn.readLine(); res =Convert(res); if(set.get(res)==null) { set.put(res,1); }else { int newValue = set.get(res)+1; set.put(res,newValue); } } if(set.keySet().size()==num) { System.out.println("No duplicates."); } else { List<Map.Entry<String,Integer>> infoIds = new ArrayList<Map.Entry<String,Integer>>(set.entrySet()); Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { // return (o2.getValue() - o1.getValue()); //降序 return (o1.getKey().charAt(0) - o2.getKey().charAt(0)); //升序 } }); for(int i=0;i<infoIds.size();i++) { if(infoIds.get(i).getValue()>1) { String result=""; result=infoIds.get(i).getKey()+" "+infoIds.get(i).getValue(); System.out.println(result); } } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator