1 solutions

  • 0
    @ 2025-11-15 17:31:03
    #include <bits/stdc++.h>
    using namespace std;
    struct node
    {
        string str1, str2;
    };
    
    bool cmp(node a, node b)
    {
        if (a.str1 != b.str1)
            return a.str1 < b.str1;
        else
            return a.str2 < b.str2;
    }
    
    void info1() // 结构体
    {
        int n;
        cin >> n;
        vector<node> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i].str1 >> a[i].str2;
        }
        sort(a.begin(), a.end(), cmp);
        // sort(a.begin(), a.end(), [](node x, node y)
        //      {
        //     if(x.str1!=y.str1)return x.str1<y.str1;
        //     else return x.str2<y.str2; });
    
        node bef;
        int ans = 0;
        for (auto e : a)
        {
            if (e.str1 != bef.str1 || e.str2 != bef.str2)
            {
                ans++;
                bef = e;
            }
        }
        cout << ans << endl;
    }
    
    void info2() // set自带去重
    {
        int n;
        cin >> n;
        set<string> a;
        for (int i = 0; i < n; i++)
        {
            string t1, t2;
            cin >> t1 >> t2;
            a.insert(t1 + " " + t2);
        }
        cout << a.size() << endl;
    }
    
    int main()
    {
        info1();
        return 0;
    }
    

    Information

    ID
    7104
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    (None)
    # Submissions
    52
    Accepted
    25
    Uploaded By