输出问题
求助成绩排序的题
同样的测试用例,我在本地的输出是对的,但提交后就不对了
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef struct {
string name;
int score;
}student;
bool cmp1(student a, student b)
{
return a.score > b.score;
}
bool cmp2(student a, student b)
{
return a.score < b.score;
}
int main()
{
student stu[1001]; //存储信息
int num;
int type; //0降序,1升序
cin >> num >> type;
for (int i = 0; i < num; i++) //录入信息
{
cin >> stu[i].name >> stu[i].score;
}
if (type == 0) //排序
{
sort(stu, stu + num, cmp1);
}
else
{
sort(stu, stu + num, cmp2);
}
cout << "***********************************" << endl;
for (int i = 0; i < num; i++) //输出
{
cout << stu[i].name << " " << stu[i].score << endl;
}
return 0;
} 这是我本地输出的答案: 这是报错的:
有人知道这是为啥吗??谢谢~~
#笔试题目#
查看2道真题和解析
