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

PAT 1083 List Grades

时间:2014-11-04 01:33:12      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   for   sp   div   

#include <cstdio>
#include <cstdlib>

using namespace std;

class Stu {
    public:
        char name[12];
        char id[12];
};

int main() {
    int N = 0;
    // because all the grades are distinct & grade in range of [0, 100]
    // use simplified bucket sort here
    Stu* stu[101] = {0};
    int grade;
    scanf("%d", &N);
    for (int i=0; i<N; i++) {
        Stu* tmp = new Stu();
        scanf("%s%s%d", tmp->name, tmp->id, &grade);
        stu[grade] = tmp;
    }
    
    int lo, hi;
    scanf("%d%d", &lo, &hi);
    if (lo > hi) {
        int tmp = lo;
        lo = hi;
        hi = tmp;
    }
    bool has = false;
    for (int i=hi; i>=lo; i--) {
        if (stu[i] == NULL) continue;
        has = true;
        printf("%s %s\n", stu[i]->name, stu[i]->id);
    }
    if (!has) {
        printf("NONE");
    }
    return 0;
}

完成每日任务,睡觉了可以!

PAT 1083 List Grades

标签:des   style   blog   io   color   ar   for   sp   div   

原文地址:http://www.cnblogs.com/lailailai/p/4072626.html

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