map 经典写法

jinpeiyu 2023-12-09 14:09:32 6 返回题目

#include <bits/stdc++.h>
using namespace std;
map<string, int> dictionary;
int main() {
    int n, m, page;
    string word;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> word >> page;
        dictionary[word] = page;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> word;
        cout << dictionary[word] << endl;
    }
    return 0;
}

用MAP!!!

{{ vote && vote.total.up }}