#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
using namespace std;
struct book {
char name[20];
int yue;
int ri;
};
int cmp(book a, book b) {
int t = 0;
t = strcmp(a.name, b.name);
if (a.yue != b.yue)
return a.yue < b.yue;
else if (a.ri != b.ri)
return a.ri < b.ri;
else if (strlen(a.name) != strlen(b.name))
return strlen(a.name) < strlen(b.name);
return a.name < b.name;
}
int main()
{
int n;
cin >> n;
struct book student[180];
for (int i = 0; i < n; i++) {
cin >> student[i].name;
cin >> student[i].yue;
cin >> student[i].ri;
}
sort(student, student + n-1, cmp);
cout << "name" << "-----" << "age" <<"-----"<< "grade" << endl;
int flag = 0;
struct wenee same[90];
int h = 0;
int g = 0;
for (int i = 0; i < n; i++) {
cout << student[i].name << student[i].yue << student[i].ri << endl;
//if (student[i].yue == student[i + 1].yue && student[i].ri == student[i + 1].ri)
//{
//same[h].yue = student[i].yue;
//same[h].ri = student[i].ri;
//strcpy_s(same[h].xingming[g],student[i].name);
//g++;
//}
//h++;
}
}
求大神解答,为何我这里总是显示invalid comparator?是我的cmp函数定义的有错吗?
原问题:每组生日相同的学生,输出一行,其中前两个数字表示月和日,后面跟着所有在当天出生的学生的名字,数字、名字之间都用一个空格分隔。对所有的输出,要求按日期从前到后的顺序输出。 对生日相同的名字,按名字从短到长按序输出,长度相同的按字典序输出。如没有生日相同的学生,输出”None”