-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1022.cpp
185 lines (175 loc) · 3.56 KB
/
1022.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<iostream>
#include<sstream>
#include<string>
#include<map>
using namespace std;
#define DEBUG
int main()
{
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
int n,m;
map<string,set<string> > titleMap;
map<string,set<string> > authorMap;
map<string,set<string> > publisherMap;
map<string,set<string> > yearMap;
map<string,set<string> > keyMap;
cin>>n;
string dummy;
getline(cin,dummy);
for(int i=0;i<n;i++)
{
string id,title;
getline(cin,id);
//title
getline(cin,title);
if(titleMap.count(title) == 0)
{
set<string> s;
s.insert(id);
titleMap[title]=s;
}
else
{
map<string,set<string> >::iterator it=titleMap.find(title);
set<string> s=it->second;
s.insert(id);
titleMap[title]=s;
}
//author
string author;
getline(cin,author);
if(authorMap.count(author) == 0)
{
set<string> s;
s.insert(id);
authorMap[author]=s;
}
else
{
map<string,set<string> >::iterator it=authorMap.find(author);
set<string> s=it->second;
s.insert(id);
authorMap[author]=s;
}
//key words
string keywords;
getline(cin,keywords);
istringstream ist(keywords);
while(!ist.eof())
{
string key;
ist>>key;
if(keyMap.count(key) == 0)
{
set<string> s;
s.insert(id);
keyMap[key]=s;
}
else
{
map<string,set<string> >::iterator it=keyMap.find(key);
set<string> s=it->second;
s.insert(id);
keyMap[key]=s;
}
}
//publisher
string publisher;
getline(cin,publisher);
if(publisherMap.count(publisher) == 0)
{
set<string> s;
s.insert(id);
publisherMap[publisher]=s;
}
else
{
map<string,set<string> >::iterator it=publisherMap.find(publisher);
set<string> s=it->second;
s.insert(id);
publisherMap[publisher]=s;
}
//year
string year;
getline(cin,year);
if(yearMap.count(year) == 0)
{
set<string> s;
s.insert(id);
yearMap[year]=s;
}
else
{
map<string,set<string> >::iterator it=yearMap.find(year);
set<string> s=it->second;
s.insert(id);
yearMap[year]=s;
}
}
cin>>m;
getline(cin,dummy);
for(int i=0;i<m;i++)
{
string query;
getline(cin,query);
cout<<query<<endl;
set<string> results;
string newquery=query.substr(3,query.length()-3);
switch(query.at(0))
{
case '1':
if(titleMap.count(newquery) == 1)
{
map<string,set<string> >::iterator it=titleMap.find(newquery);
results=it->second;
}
break;
case '2':
if(authorMap.count(newquery) == 1)
{
map<string,set<string> >::iterator it=authorMap.find(newquery);
results=it->second;
}
break;
case '3':
if(keyMap.count(newquery) == 1)
{
map<string,set<string> >::iterator it=keyMap.find(newquery);
results=it->second;
}
break;
case '4':
if(publisherMap.count(newquery) == 1)
{
map<string,set<string> >::iterator it=publisherMap.find(newquery);
results=it->second;
}
break;
case '5':
if(yearMap.count(newquery) == 1)
{
map<string,set<string> >::iterator it=yearMap.find(newquery);
results=it->second;
}
break;
}
if(results.size()!=0)
{
vector<string> v;
for(set<string>::iterator it=results.begin();it!=results.end();it++)
v.push_back(*it);
sort(v.begin(),v.end());
for(int j=0;j<v.size();j++)
cout<<v[j]<<endl;
}
else
cout<<"Not Found"<<endl;
}
return 0;
}