本题题意很好读,看上去也不难写
写完运行才发现输出title只有一个单词...
后来把cin >> t换成了getline(cin, t)
还有一个坑点:
Line #1: the 7-digit ID number;
故输出要用%07d
采用的数据结构是map<string, set
开了很多这样的map
还有key的读入,也需要记忆
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
bool Sqrt(LL n) { return (LL)sqrt(n) * sqrt(n) == n; }
const double PI = acos(-1.0), ESP = 1e-10;
const LL INF = 99999999999999;
const int inf = 999999999;
int N, M;
map<string, set<int> > title, author, key, pub, year;
void Q(map<string, set<int> > & mp, string & str)
{
if(mp.find(str) != mp.end()) {
for(auto u : mp[str]) printf("%07d\n", u);
// for(set<int>::iterator it = mp[str].begin(); it != mp[str].end(); it++)
// printf("%07d\n", *it);
}
else puts("Not Found");
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
scanf("%d", &N);
for(int i = 0; i < N; i++) {
int id; scanf("%d\n", &id);
string t; getline(cin, t);
title[t].insert(id);
getline(cin, t); author[t].insert(id);
while(cin >> t) {
key[t].insert(id);
if(getchar() == '\n') break;
}
getline(cin, t); pub[t].insert(id);
getline(cin, t); year[t].insert(id);
}
scanf("%d", &M);
while(M--) {
int num;
string s;
scanf("%d: ", &num);
getline(cin, s);
cout << num << ": " << s << "\n";
if(num == 1) Q(title, s);
else if(num == 2) Q(author, s);
else if(num == 3) Q(key, s);
else if(num == 4) Q(pub, s);
else if(num == 5) Q(year, s);
}
return 0;
}
/*
input:
output:
modeling:
methods:
complexity:
summary:
*/