You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

#include <bits/stdc++.h>
using namespace std;
struct Student {
string name;
int month;
int day;
bool havePrint = false;//是不是输出过了
};
//对比的方法
/*
用大于号就是从大到小排序,用小于号就是从小到大排序
*/
bool cmp(const Student &x, const Student &y) {
if (x.month == y.month) {
if (x.day == y.day) {
if (x.name.length() == y.name.length()) {
return x.name < y.name;
} else {
return x.name.length() < y.name.length();
}
}
return x.day < y.day;
}
return x.month < y.month;
}
int main() {
int n;
cin >> n;
Student *s = new Student[n];
for (int i = 0; i < n; ++i) {
cin >> s[i].name >> s[i].month >> s[i].day;
}
//排序,按生日大小排序
sort(s, s + n, cmp);
//查找一样的生日
for (int i = 0; i < n - 1; ++i) {
if (!s[i].havePrint) {
int count = 0;
vector<string> v1;
for (int j = i + 1; j < n; ++j) {
if (s[i].month == s[j].month && s[i].day == s[j].day) {
v1.push_back(s[j].name);
s[j].havePrint = true;
count++;
}
}
if (count > 0) {
v1.insert(v1.begin(), s[i].name);
cout << s[i].month << " " << s[i].day << " ";
for (int j = 0; j < v1.size(); ++j) {
cout << v1[j] << " ";
}
cout << endl;
}
}
}
//删除动态数组
delete[]s;
return 0;
}