PAT 甲级 A1083 (2019/02/17)

#include<cstdio>
#include<cstring>
#include<algorithm>         // STL 
using namespace std;        //使用sort()函数必须加上 
const int MAXN = 50;
struct Student{
    char name[15];
    char id[15];
    int score;
}stu[MAXN];
bool cmp(Student a, Student b){
    return a.score > b.score;   //按照分数排序,从大到小               
}
int main(){
    int n; 
    scanf("%d", &n);        //总人数
    for(int  i = 0; i < n; i++){
        scanf("%s %s %d", stu[i].name, stu[i].id, &stu[i].score);    
    }
    sort(stu, stu + n, cmp);        //排序 
    int start, end;
    bool flag = false;
    scanf("%d %d", &start, &end);   
    for(int  i = 0; i < n; i++){
        if(stu[i].score >= start && stu[i].score <= end){
            printf("%s %s\n", stu[i].name, stu[i].id);
            flag = true;
        }
    }
    if(flag == false){
        printf("NONE\n");   //出错了,题目里是大写,而我写成了None 
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zjsaipplp/p/10425248.html