A1039 Course List for Student (25)

摘要
Title: A1039 Course List for Student (25)
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

A1039 Course List for Student (25)

  • 题意

    Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.

  • 思路

    按题意模拟即可

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    /*
    * @Author: NEFU AB-IN
    * @Date: 2023-01-09 13:35:57
    * @FilePath: \GPLT\A1039\A1039.cpp
    * @LastEditTime: 2023-01-09 13:42:09
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    #undef int

    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr)
    #define DEBUG(X) cout << #X << ": " << X << '\n'
    typedef pair<int, int> PII;

    const int N = 1e5 + 10, INF = 0x3f3f3f3f;

    int n, k;
    unordered_map<string, vector<int>> g;

    signed main()
    {
    IOS;
    cin >> n >> k;
    for (int i = 0; i < k; ++i)
    {
    int idx, m;
    cin >> idx >> m;
    for (int j = 0; j < m; ++j)
    {
    string s;
    cin >> s;
    g[s].push_back(idx);
    }
    }
    for (int i = 0; i < n; ++i)
    {
    string s;
    cin >> s;
    cout << s << " " << SZ(g[s]);
    sort(ALL(g[s]));
    for (int j = 0; j < SZ(g[s]); ++j)
    {
    cout << " " << g[s][j];
    }
    cout << '\n';
    }
    return 0;
    }
使用搜索:谷歌必应百度