总时间限制: 1000ms 内存限制: 65536kB
描述
在一个有180人的大班级中,存在两个人生日相同的概率非常大,现给出每个学生的名字,出生月日。试找出所有生日相同的学生。
输入
第一行为整数n,表示有n个学生,n ≤ 180。此后每行包含一个字符串和两个整数,分别表示学生的名字(名字第一个字母大写,其余小写,不含空格,且长度小于20)和出生月(1 ≤ m ≤ 12)日(1 ≤ d ≤ 31)。名字、月、日之间用一个空格分隔
输出
每组生日相同的学生,输出一行,其中前两个数字表示月和日,后面跟着所有在当天出生的学生的名字,数字、名字之间都用一个空格分隔。对所有的输出,要求按日期从前到后的顺序输出。 对生日相同的名字,按名字从短到长按序输出,长度相同的按字典序输出。如没有生日相同的学生,输出”None”
样例输入
6 Avril 3 2 Candy 4 5 Tim 3 2 Sufia 4 5 Lagrange 4 5 Bill 3 2
样例输出
3 2 Tim Bill Avril 4 5 Candy Sufia Lagrange
这题一开始我思路就是对的 但是在7分卡住了好久
原因是没有想到他的名字可以重复 所以我把set改成multiset就可以储存重复名字的
总结:考虑不周全
#include<bits/stdc++.h>
using namespace std;
struct Rule {
bool operator()(const string& s1, const string& s2)const {
if (s1.length() == s2.length()) return s1 < s2;
else return s1.length() < s2.length();
}
};
multiset<string, Rule> st[15][35];
int main() {
int n, m, d, fg = 0; cin >> n;
string s;
while (n--) {
cin >> s >> m >> d;
st[m][d].insert(s);
}
for (int i = 1; i <= 12; ++i) {
for (int j = 1; j <= 31; ++j) {
if (st[i][j].size() >= 2) {
fg = 1;
cout << i << ' ' << j;
for (auto e : st[i][j]) {
cout << ' ' << e;
}
cout << endl;
}
}
}
if (fg == 0) puts("None");
return 0;
}