C language performance statistics

Welcome to the world of my C language

topic

Problem Description

After the college entrance examination results came out, the universities began to admit students according to the scores.

However, only sorting the scores from high to low fails to show the characteristics of the normal distribution curve of scores. The teachers in charge of enrollment work want to count the number of students in certain "score segments".

Due to the large number of people taking the exam, I hope you can help with programming.

Input

There are multiple sets of input data for this question, and you must process it until EOF.

The first line of each group of data is an integer N representing the total number of people taking the test (1<=N<=10,000). The second line is N integers, representing the scores of these N candidates, and the score range of the candidates is [0…100].

The third line is an integer Q (1<=Q<=1,000) indicating the number of queries made by the teacher. In the next line Q, two integers L, H (0≤L≤H≤100) indicate that the teacher wants to query in [ L...H] The number of students in this segment.

Output

For each query, output a row, indicating the number of students in the query score section.

Sample Input

3
10 20 30
3
5 100
10 20
0 10

Sample Output

3
2
1

answer

Shown below 实现代码.

#include <iostream>
#include <stdio.h>
using namespace std;
int a[10007];
struct node
{
    
    
	int begin;
	int end;
}b[1007];
int main()
{
    
    
	int n;
	while(scanf("%d",&n) != EOF)
	{
    
    
		for(int i = 0; i < n; i++)
		{
    
    
			scanf("%d",&a[i]);
		}
		int t;
		scanf("%d",&t);
		for(int j = 0; j < t; j++)
		{
    
    
			int num = 0;
			scanf("%d%d",&b[j].begin,&b[j].end);
			for(int i = 0; i < n; i++)
			{
    
    
				if(a[i] >= b[j].begin &&a[i] <= b[j].end)
				{
    
    
					num++;
				}
			}
			printf("%d\n",num);
		}
	}
	return 0;
} 

Thoughts on this question

The content of this block may come from textbooks or other websites. If infringement is involved, please contact me to delete it. Thank you~

The structure is used, which is quite simple overall

the above.

Guess you like

Origin blog.csdn.net/hongguoya/article/details/106451262