本題要求讀入 N 名學(xué)生的成績,將獲得某一給定分數(shù)的學(xué)生人數(shù)輸出。
輸入格式:
輸入在第 1 行給出不超過 10 ?5 ?? 的正整數(shù) N,即學(xué)生總?cè)藬?shù)。隨后一行給出 N 名學(xué)生的百分制整數(shù)成績,中間以空格分隔。最后一行給出要查詢的分數(shù)個數(shù) K(不超過 N 的正整數(shù)),隨后是 K 個分數(shù),中間以空格分隔。
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])]);}}