码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 甲级 A1083 (2019/02/17)

时间:2019-02-24 10:24:42      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:sort   使用   \n   amp   std   str   end   algo   i++   

#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;
}

PAT 甲级 A1083 (2019/02/17)

标签:sort   使用   \n   amp   std   str   end   algo   i++   

原文地址:https://www.cnblogs.com/zjsaipplp/p/10425248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!