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 |
一直runtime 测试用例也是都过了package com.company; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int count = cin.nextInt(); HashMap<String, Integer> hm = new HashMap<String, Integer>(); for(int i=0;i<count;i++){ String input = cin.next(); if(input==""||input==null){ i--; continue; } input = input.toUpperCase(); StringBuffer stringBuffer = new StringBuffer(); for(int j=0;j<input.length();j++){ int charactor = input.charAt(j); if(charactor!=45){ if(charactor<64){ stringBuffer.append(input.charAt(j)); }else{ int index = charactor - 65; int muti = index / 3; if(charactor==89) muti=7; stringBuffer.append(muti+2); } } if(stringBuffer.length()==3){ stringBuffer.append('-'); } } String s = stringBuffer.toString(); Integer integer = hm.get(s); if(integer==null){ integer=0; } hm.put(s,integer+1); } Set<String> strings = hm.keySet(); Iterator<String> iterator = strings.iterator(); while (iterator.hasNext()) { String next = iterator.next(); System.out.println(next+' '+hm.get(next)); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator