题解 | 2024_手机基站_1551

2024_手机基站_1551

https://www.nowcoder.com/practice/a0f8922d8b1444e7a005f5de30edc98b

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct Person {
    string phone;
    char seq;
    string start, end;

    Person(string phone, char seq, string start, string end) : phone(phone), seq(seq), start(start), end(end) {}

};

int main() {
    int n;
    cin >> n;
    vector<Person> persons;
    while (n--) {
        string phone, start, end;
        char seq;
        cin >> phone >> seq >> start >> end;
        persons.emplace_back(phone, seq, start, end);
    }
    sort(persons.begin(), persons.end(),
         [](const auto &a, const auto &b) { return a.start == b.start ? a.phone < b.phone : a.start < b.start; });
    string s;
    cin >> s;
    vector<Person> res;
    for (const auto &person:persons) if (person.phone == s) res.emplace_back(person);
    for (const auto &person:persons) {
        for (const auto &a:res) {
            if (s != person.phone && a.seq == person.seq && a.start <= person.end && a.end >= person.start) {
                cout << person.phone << " " << person.seq << " " << person.start << " " << person.end << endl;
                break;
            }
        }
    }
    return 0;
}

全部评论

相关推荐

牛马人的牛马人生:太舒服了接接接
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务