输出输入数据比较多
使用scanf、printf
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 100010;
int n;
char C;
struct Student
{
string id, name;
int grade;
char c;
} stds[N];
bool cmp1(Student a, Student b)
{
return a.id < b.id;
}
bool cmp2(Student a, Student b)
{
if(a.name != b.name) return a.name < b.name;
else return a.id < b.id;
}
bool cmp3(Student a, Student b)
{
if(a.grade != b.grade) return a.grade < b.grade;
else return a.id < b.id;
}
int main()
{
cin >> n >> C;
for (int i = 0; i < n; i ++ )
{
char id[10], name[10];
int grade;
scanf("%s%s%d", id, name, &grade);
stds[i] = {id, name, grade, C};
}
if(C == '1') sort(stds, stds + n, cmp1);
else if(C == '2') sort(stds, stds + n, cmp2);
else sort(stds, stds + n, cmp3);
for(int i = 0; i < n; i ++)
{
printf("%s %s %d\n", stds[i].id.c_str(), stds[i].name.c_str(), stds[i].grade);
}
return 0;
}