'commit'
This commit is contained in:
63
TangDou/XiTi/1362.cpp
Normal file
63
TangDou/XiTi/1362.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user