迅為i.MX6ULL開發板按鍵例程編譯及執行
阿新 • • 發佈:2021-07-13
卡在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\n", all_student_num); for (int j = 0; j < all_student_num; ++j) { printf("%s %d %d %d\n", stu[j].id, stu[j].all_num, stu[j].group, stu[j].group_num); } }