E. 【例题5】生日相同

在这里插入图片描述
在这里插入图片描述

解析

字符串操作,本题解采取了多关键词排序

Code

#include <bits/stdc++.h>
using namespace std;

int f, n;
struct node
{
    int y, r;
    string s;
}a[100005];

int cmp (node x, node y)
{
    if (x.y != y.y) return x.y < y.y;
    if (x.r != y.r) return x.r < y.r;
    if (x.s.length () != y.s.length ()) return x.s.length () < y.s.length ();
    return x.s < y.s;
}

int main ()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> a[i].s >> a[i].y >> a[i].r;
    sort (a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; ++ i)
    {
        if (a[i].y == a[i + 1].y && a[i].r == a[i + 1].r)
        {
            cout << a[i].y << ' ' << a[i].r << ' ' << a[i].s << ' ';
            f = true;
            while (a[i].y == a[i + 1].y && a[i].r == a[i + 1].r)
            {
                i ++;
                cout << a[i].s << ' ';
            }
            cout << endl;
        }
    }
    if (!f) cout << "None" << endl;
    return 0;
} 

 

posted @ 2021-03-26 20:25  unknown_future  阅读(122)  评论(0编辑  收藏  举报