PAT B 1038 (C ++) - Long brush brother's title path

1038 statistics with student achievement (20 points)
This question requires students to read N results, will receive a certain number of students to a given fraction of the output.

Input format:
input gives no more than 10 ^ 5 N is a positive integer in the first line, i.e., the total number of students. Then given N line student score percentile integer, separated by a space. The number score given to the last row of the query K (N is a positive integer not exceeding), followed by the K fractions, separated by a space.

Output Format:
In line given in the query sequence is equal to the number of students scoring a specified fraction, separated by a space, but the end of the line may not have the extra space.

Sample input:
10
60 75 90 55 99 82 90 75 50 75
. 3 75 90 88

Output Sample:
320

#include<iostream>
#include<algorithm>
#include<map>
using namespace  std;
int main(){
	int num = 0,num2=0;
	cin >> num;
	int number[100001];
	int k[100001];
	map<int, size_t> grade;
	for (int i = 0; i < num; i++){
		cin >> number[i];
		++grade[number[i]];
	}
	cin >> num2;
	for (int i = 0; i < num2; i++){
		cin >> k[i];
	}
	for (int i = 0; i < num2; i++){
		if (i != num2 - 1){
			cout << grade[k[i]] << " ";
		}
		else{
			cout << grade[k[i]] << endl;
		}
	}
	return 0;
}
Published 46 original articles · won praise 0 · Views 584

Guess you like

Origin blog.csdn.net/qq_23079139/article/details/104101397