3243. 搜索联系人

Fifnmar
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Person {
    string name;
    string number;
};

inline void solve(int i) {
    int n;
    cin >> n;
    Person *a = new Person[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i].name >> a[i].number;
    }
    string frag;
    cin >> frag;
    cout << "case #" << i << ":\n";
    vector<Person *> ok;
    for (int i = 0; i < n; ++i) {
        if (a[i].number.find(frag) != string::npos) {
            ok.push_back(a + i);
        }
    }
    sort(ok.begin(), ok.end(), [](Person *a, Person *b) {
        if (a->name < b->name)
            return true;
        if (b->name < a->name)
            return false;
        return a->number < b->number;
    });
    cout << ok.size() << '\n';
    for (auto i : ok)
        cout << i->name << ' ' << i->number << '\n';
    delete[] a;
}

int main() {
    int t;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> t;
    for (int i = 0; i < t; ++i) {
        solve(i);
    }
}
computerLearner

为啥983行过不去????

你当前正在回复 博客/题目
存在问题!