zoukankan      html  css  js  c++  java
  • PAT 1025

    卡在sort的cmp上了

    忘记对id排序了

    #include<iostream>
    #include<vector>
    #include <unordered_set>
    #include <unordered_map>
    #include <cstring>
    #include <stdio.h>
    #include <algorithm>
    
    using namespace std;
    struct Student{
        char id[15];
        int group;
        int score;
        int group_num;
        int all_num;
    
    };
    Student stu[50000];
    bool cmp(Student s1,Student s2){
        if(s1.score!=s2.score)
        return s1.score>s2.score;
        else{
            return strcmp(s1.id,s2.id)<0;
        }
    }
    int main() {
        int group_num;
        scanf("%d", &group_num);
        int now_group = 1;
        int all_student_num = 0;
        int i = 0;//student[i]
        while (now_group <= group_num) {//别忘更新new_group
            int student_num;
            scanf("%d", &student_num);
            all_student_num += student_num;
            int student_num1 = student_num;
            int q=i;
            while (student_num--) {
                scanf("%s %d", stu[i].id, &stu[i].score);
                stu[i].group = now_group;
                i++;
            }
            sort(stu + q, stu + q + student_num1, cmp);
            int mingci = 1;
    
            stu[q].group_num = mingci;
            mingci++;
            for (int j = 1; j < student_num1; ++j) {
    
                if (stu[q + j].score == stu[q + j - 1].score) {
    
                    stu[q + j].group_num = stu[q + j - 1].group_num;
                    mingci++;
                } else {
                    stu[q + j].group_num = mingci;
                    mingci++;
                }
    
            }
            now_group++;
    
        }
        sort(stu, stu + all_student_num, cmp);
        int mingci = 1;
        stu[0].all_num = mingci;
        mingci++;
        for (int j = 1; j < all_student_num; ++j) {
            if (stu[j].score == stu[j - 1].score) {
                stu[j].all_num = stu[j - 1].all_num;
                mingci++;
            } else {
                stu[j].all_num = mingci;
                mingci++;
            }
    
        }
        printf("%d
    ", all_student_num);
        for (int j = 0; j < all_student_num; ++j) {
            printf("%s %d %d %d
    ", stu[j].id, stu[j].all_num, stu[j].group, stu[j].group_num);
    
        }
       
    
    
    }
    
    为了自己,和那些爱你的人
  • 相关阅读:
    前端模板Nunjucks简介
    git提交时支持文件名大小写的修改
    多行文本加省略号的处理方法
    前端性能优化实践方案总结
    使用gulp工具生成svgsprites
    koa简介
    JSX语法简介
    踩坑所引发出的appendChild方法的介绍
    React业务实践
    javascript--数组
  • 原文地址:https://www.cnblogs.com/zhmlzhml/p/15021380.html
Copyright © 2011-2022 走看看