PAT 甲级 A1025 (2019/02/17)

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 30010;
struct Student{
    char id[15];
    int score;
    int local_number;
    int local_rank;
}stu[maxn];
bool cmp(Student a, Student b){
    if(a.score != b.score) return a.score > b.score;
    else return strcmp(a.id, b.id) < 0;
}
int main(){
    int test_room_number, examinee_number, acount_stu = 0;
    scanf("%d", &test_room_number);
    for(int i = 0; i < test_room_number; i++){
        scanf("%d", &examinee_number);
        for(int j = 0; j < examinee_number; j++){
            scanf("%s %d", stu[acount_stu].id, &stu[acount_stu].score);
            stu[acount_stu].local_number = i + 1;
            acount_stu++;
        }
        sort(stu + acount_stu - examinee_number, stu + acount_stu, cmp);
        stu[acount_stu - examinee_number].local_rank = 1;
        for(int k = acount_stu - examinee_number + 1; k < acount_stu; k++){
            if(stu[k].score == stu[k - 1].score){
                stu[k].local_rank = stu[k - 1].local_rank;
            }else{
                stu[k].local_rank = k + 1 - (acount_stu - examinee_number);
            }
        }
    }
    printf("%d\n", acount_stu);
    sort(stu, stu + acount_stu, cmp);
    int r = 1;
    for(int j = 0; j < acount_stu; j++){
        if(j > 0 && stu[j].score != stu[j - 1].score){
            r = j + 1;
        }
        printf("%s %d %d %d\n",stu[j].id, r, stu[j].local_number, stu[j].local_rank);
    }
    return 0;
}

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

时间: 2024-08-30 02:37:22

PAT 甲级 A1025 (2019/02/17)的相关文章

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 &g

PAT 甲级 A1028 (2019/02/17)

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN = 100010; struct Student{ int id; char name[10]; int score; }stu[MAXN]; bool cmp1(Student a, Student b) { return a.id < b.id; //从小到大 } bool cmp

PAT 甲级 A1055 (2019/02/17)

#include<cstdio> #include<cstring> #include<algorithm> // STL using namespace std; //使用sort()函数必须加上 const int MAXN = 100010; struct TH{ char name[15]; int age; int money; }th[MAXN], valid[MAXN]; int Age[MAXN] = {0}; //某年龄人数,下标代表人数 bool c

PAT甲级——A1025 PAT Ranking

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it i

PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone c

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

【谜客帝国】第147届月思主擂谜会(2019.02.15)

 [谜客帝国]第147届月思主擂谜会(2019.02.15) 主持计分:东东 1.“人在中天日月间”(9笔字)春/月思 [注:面出陈孚<开平即事二首>,“势超大地山河上,-.”] 2. 玉漏声中烟气袅(3字法国奢侈品牌)YSL/月思 3. 双双相念初相爱(2字著名动漫人物)菜菜/月思 4.“数点燕云州外.雪霜威”(足球用语二,4+3)4132.451/月思 [注:面出余文<相见欢>,“登高望断龙旗,未曾归.几度中原北定,梦依稀.朔风乱,胡尘漫,掩斜晖.-.”] 5.“十载同心如一人

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.

解题报告 smoj 2019初二创新班(2019.3.17)

目录 解题报告 smoj 2019初二创新班(2019.3.17) T1:找玩具 题目描述 题意转化 分析 代码 优化(代码复杂度) T2:闯关游戏 题目描述 分析 代码 T3:子数组有主元素 题目描述 分析 代码(\(O(nm\log n)\)) 优化 代码(\(O(nm)\)) 解题报告 smoj 2019初二创新班(2019.3.17) 时间:2019.3.21 T1:找玩具 题目描述 在游戏开始之前,游戏大师在房间的某些地方隐藏了N个玩具.玩具编号为1到N.您的任务是尽可能多地找到这些玩