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实现,不知道哪错了,大牛指出,多谢!!!!import java.util.*; public class P2945 { /** * @param args */ public static void main(String[] args) { // TODO 自动生成方法存根 Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); String input=""; //每行输入 HashMap<String,Integer> hm=new HashMap<String,Integer>();//字符串及其出现次数对 while(!(n==0&&m==0)) { int [] count=new int[n];//表示重复次数的人的个数,例如count[1]表示重复一次的字符串的个数 for(int i=0;i<n;i++) { input=sc.next(); if(!hm.containsKey(input)) { hm.put(input, 0); } else { Integer value= hm.get(input); value++; hm.remove(input); hm.put(input, value); } } Set s=hm.keySet(); Iterator it=s.iterator(); while(it.hasNext()) { count[hm.get(it.next())]++; } for(int i=0;i<n;i++) { System.out.println(count[i]); } n=sc.nextInt(); m=sc.nextInt(); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator