PAT 1022 Digital Library(测试点3,4是输出格式问题)

    技术2022-07-11  60

    #include <iostream> #include <string> #include <map> #include <set> using namespace std; void Find(map<string, set<int>>&list, string &x) { if (list.find(x) == list.end()) cout << "Not Found" << endl; else { for (set<int>::iterator it = list[x].begin(); it != list[x].end(); it++) { //cout << *it<<endl; printf("d\n", *it);//测试点3,4都卡在这一句,是代号少于7,需要维持格式 } } } int main() { int n; cin >> n; map<string, set<int>>namel,authorl,keyl,publisherl,yearl; while (n--) { int num; cin >> num; getchar(); string temp; getline(cin, temp);//代号 namel[temp].insert(num);//书名 getline(cin, temp); authorl[temp].insert(num);//作者 while (cin >> temp) { keyl[temp].insert(num);//key char c = getchar(); if (c == '\n')break; } getline(cin, temp); publisherl[temp].insert(num);//出版社 getline(cin, temp); yearl[temp].insert(num);//年份 } int m; cin >> m; while (m--) { int type; cin >> type; cout << type << ": "; getchar(); getchar(); string temp; getline(cin, temp); //getchar(); cout << temp << endl; switch (type) { case 1: Find(namel, temp); break; case 2: Find(authorl, temp); break; case 3: Find(keyl, temp); break; case 4: Find(publisherl, temp); break; case 5: Find(yearl, temp); break; } } system("pause"); return 0; }
    Processed: 0.009, SQL: 9