题目10 统计同成绩学生人数

 

 1 import java.util.HashMap;
 2 import java.util.Map;
 3 import java.util.Scanner;
 4  
 5 public class Main{
 6     public static void main(String[] args) {
 7         Scanner in=new Scanner(System.in);
 8         Map<Integer,Integer> count=new HashMap<Integer, Integer>();
 9         while(in.hasNext()){
10             int N=in.nextInt();
11             if(N==0) break;
12             count.clear();
13             for(int i=0;i<N;i++){
14                 int x=in.nextInt();
15                 if(count.containsKey(x))
16                     count.put(x, count.get(x)+1);
17                 else
18                     count.put(x, 1);
19             }
20             int target=in.nextInt();
21             if(count.containsKey(target))
22                 System.out.println(count.get(target));
23             else
24                 System.out.println(0);
25         }
26     }
27 }
28 /**************************************************************
29     Problem: 1018
30     User: 0000H
31     Language: Java
32     Result: Accepted
33     Time:360 ms
34     Memory:26680 kb
35 ****************************************************************/

 

posted @ 2015-09-09 16:43  打小孩  阅读(304)  评论(0编辑  收藏  举报