PAT Grade B 1038 Statistics for students with the same score 20 (points)

topic

This question requires reading the scores of NN N students, and outputting the number of students who have obtained a given score.

Input format:

Enter no more than given in line 1 1 0 5 10 5 1 0 ? 5 ? ? Positive integer NN N , that is, the total number of students. The next line gives the scores of NN N students in a percentile system, separated by spaces. The last line gives the number of scores to be queried KK K ( a positive integer not exceeding NN N ), followed by KK K scores, separated by spaces.

Output format:

The number of students whose scores are equal to the specified scores is given in a row in the order of query, separated by spaces, but no extra spaces are allowed at the end of the row.

Input sample:

10
60 75 90 55 75 99 82 90 75 50
3 75 90 88

Sample output:

3 2 0

Code


#include<iostream>
using namespace std;
int main()
{
    
    
	int a[101] = {
    
    0},num,i,K;
	cin >> num;
	while (num--)
	{
    
    
		cin >> i;
		a[i]++;
	}
	cin >> K;
	while (K--)
	{
    
    
		cin >> i;
		if(K==0)
			cout << a[i];
		else
			cout << a[i] << " ";
	}
	return 0;
}

Question details link

Guess you like

Origin blog.csdn.net/qq_41985293/article/details/115035336