代码如下:
cpp
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string name[200];
int month[200];
int day[200];
for (int i = 0; i < n; i++) {
cin >> name[i] >> month[i] >> day[i];
}
bool found = false;
for (int m = 1; m <= 12; m++) {
for (int d = 1; d <= 31; d++) {
vector<string> same;
for (int i = 0; i < n; i++) {
if (month[i] == m && day[i] == d) {
same.push_back(name[i]);
}
}
if (same.size() >= 2) {
found = true;
for (int i = 0; i < same.size(); i++) {
for (int j = i + 1; j < same.size(); j++) {
if (same[i].size() > same[j].size()) {
swap(same[i], same[j]);
} else if (same[i].size() == same[j].size() && same[i] > same[j]) {
swap(same[i], same[j]);
}
}
}
cout << m << " " << d << " ";
for (int i = 0; i < same.size(); i++) {
cout << same[i] << " ";
}
cout << endl;
}
}
}
if (!found) {
cout << "None" << endl;
}
return 0;
}
网站链接:https://bas.ssoier.cn/problem_show.php?pid=3371
创作不易,给个关注吧🦀🦀