#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
using namespace std;
struct Student
{
string ID;
char rank;
string room;
string date;
int score;
};
bool Mycompare(Student& S1, Student& S2)
{
if (S1.score == S2.score)
{
return S1.ID > S2.ID;
}
return S1.score > S2.score;
}
struct Info {
string s;
char level;
string room;
string date;
string id;
int score;
};
int main()
{
int N, M, i, j, k, m;
vector<Student>S;
scanf("%d %d", &N, &M);
S.resize(N);
for (i = 0;i < N;i++)
{
char temp[14];
scanf("%s %d", temp, &S[i].score);
S[i].ID = temp;
S[i].rank = S[i].ID[0];
S[i].room.resize(4), S[i].date.resize(7);
S[i].room = S[i].ID.substr(1, 3);
S[i].date = S[i].ID.substr(4, 9);
}
sort(S.begin(), S.end(), Mycompare);
for (i = 0;i < N;i++)
{
printf("%s %d\n", S[i].ID, S[i].score);
}
return 0;
}
为啥代码排序以后再打印,ID就成乱码了?
最新推荐文章于 2024-08-21 18:16:36 发布