輸入在第 1 行給出不超過 10 ?5 ?? 的正整數 N,即學生總人數。隨后一行給出 N 名學生的百分制整數成績,中間以空格分隔。最后一行給出要查詢的分數個數 K(不超過 N 的正整數),隨后是 K 個分數,中間以空格分隔。
輸出格式:
在一行中按查詢順序給出得分等于指定分數的學生人數,中間以空格分隔,但行末不得有多余空格。
輸入樣例:
10 60 75 90 55 75 99 82 90 75 50 3 75 90 88
輸出樣例:
3 2 0
思路:用循環判斷計數 代碼:
package test1;import java.io.BufferedReader;import java.io.InputStreamReader;publicclassPTA1038{publicstaticvoidmain(String[] args)throws Exception {BufferedReader br =newBufferedReader(newInputStreamReader(System.in));int[] score =newint[101];int N = Integer.parseInt(br.readLine());String[] in = br.readLine().split(" ");for(int i =0; i < N; i++){score[Integer.parseInt(in[i])]++;}String[] s = br.readLine().split(" ");int k = Integer.parseInt(s[0]);for(int i =0; i < k -1; i++){System.out.print(score[Integer.parseInt(s[i +1])]+" ");}System.out.print(score[Integer.parseInt(s[s.length -1])]);}}