-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1022_Digital Library (30).cpp
86 lines (77 loc) · 1.84 KB
/
1022_Digital Library (30).cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <vector>
using namespace std;
map<string,set<string> > note;
vector<string> vec;
void StringSplit(string s,char splitchar,vector<string>& vec)
{
if(vec.size()>0)//保证vec是空的
vec.clear();
int length = s.length();
int start=0;
for(int i=0;i<length;i++)
{
if(s[i] == splitchar && i == 0)//第一个就遇到分割符
{
start += 1;
}
else if(s[i] == splitchar)
{
vec.push_back(s.substr(start,i - start));
start = i+1;
}
else if(i == length-1)//到达尾部
{
vec.push_back(s.substr(start,i+1 - start));
}
}
}
int main()
{
int n,i,j;
int no;
string ID,title,author,keywords,publiser,year;
scanf("%d", &n);
for(i = 0; i < n; i++)
{
cin >> ID;
getchar();
getline(cin, title, '\n');
//cout << title << endl;
note[title].insert(ID);
getline(cin, author, '\n');
note[author].insert(ID);
getline(cin, keywords, '\n');
StringSplit(keywords,' ',vec);
for(int j = 0; j < vec.size(); j++)
note[vec[j]].insert(ID);
getline(cin, publiser, '\n');
note[publiser].insert(ID);
getline(cin, year, '\n');
note[year].insert(ID);
}
string ask;
scanf("%d", &n);
for(i = 0; i < n; i++)
{
scanf("%d: ", &no);
getline(cin, ask,'\n');
cout << no << ": " << ask << endl;
if(!note.count(ask))
{
puts("Not Found");
}
else
{
for(set<string>::iterator iter = note[ask].begin(); iter != note[ask].end(); iter++)
{
cout << *iter << endl;
}
}
}
return 0;
}