标签:一点 getc 查询 digital 需要 输出 string author break
while(cin >> str){
    tkey[str].insert(id);
    char c = getchar();
    if(c == '\n') break;
}#include<iostream>
#include<map>
#include<string>
#include<set>
using namespace std;
map<string, set<int> > ttitle, tkey, tauthor, tpub, tyear;
void query(map<string, set<int> > &m, string &str){
    if(m.find(str) != m.end()){
        for(auto it = m[str].begin(); it != m[str].end(); it++){
            printf("%07d\n", *it);
        }
    }else{
        printf("Not Found\n");
    }
}
int main(){
    int n, m, id, num;
    scanf("%d", &n);
    string title, key, author, pub, year;
    for(int i = 0; i < n; i++){
        scanf("%d\n", &id);
        getline(cin, title);
        ttitle[title].insert(id);
        getline(cin, author);
        tauthor[author].insert(id);
        while(cin >> key){
            tkey[key].insert(id);
            char c = getchar();
            if(c == '\n') break; 
        }
        getline(cin, pub);
        tpub[pub].insert(id);
        getline(cin, year);
        tyear[year].insert(id);
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        scanf("%d: ", &num);
        string temp;
        getline(cin, temp);
        cout << num << ": " << temp << "\n";
        if(num == 1) query(ttitle, temp);
        else if(num == 2) query(tauthor, temp);
        else if(num == 3) query(tkey, temp);
        else if(num == 4) query(tpub, temp);
        else if(num == 5) query(tyear, temp);
    }
    return 0;
}标签:一点 getc 查询 digital 需要 输出 string author break
原文地址:https://www.cnblogs.com/tsruixi/p/12245456.html