成绩统计 UESTC

来源:互联网 发布:手机可以开淘宝店铺吗 编辑:程序博客网 时间:2024/06/07 07:20

成绩统计 UESTC - 510


Problem

读入一组学生的成绩(成绩为百分制,均为整数,人数不超过10001000人),查找给定成绩区间内的学生人数。

Input

输入第一行是整数TT,表示后面测试数据的组数。对于每组数据,第一行是整数nn,表示下面一行有nn个00到100100之间的整数(学生成绩)。再下一行是整数mm(m<30m<30),表示随后有mm行整数,每行整数由两个整数aa和bb构成,aa与bb之间有一个空格,表示要查找的分数区间,且a≤ba≤b。两组测试数据之间有一个空行。

Output

对于每一组区间,输出位于该区间学生的人数,占一行。在每组测试数组后输出一个空行。

Sample Input

2
10
12 67 87 100 0 45 88 99 97 67
6
0 100
67 67
11 90
12 88
90 95
45 67

51
85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 25 24 51 15 13 39 67 97 19 76 12 33 99 18 92 35 74 0 95 71
3
33 39
32 37
45 57

Sample Output

10
2
6
6
0
3

4
2
5

ps:水题

代码如下:

#include<iostream>  #include<cstdio>  #include<cstring>  #include<algorithm> #include<string.h> using namespace std; int a[1010];int main () {    int t;    scanf("%d", &t);    while( t-- ) {        int n, m;        scanf("%d", &n);        for(int i = 1; i <= n; i++)             scanf("%d", &a[i]);        scanf("%d", &m);        while( m-- ) {            int b, c;            int sum = 0;            scanf("%d %d", &b, &c);            for(int i = 1; i <= n; i++)                 if(a[i] <= c && a[i] >= b)                     sum++;            printf("%d\n", sum);        }        printf("\n");    }    return 0;}