pat 1022 (真tm费劲)

一点教训

在输入数字之后要使用getline()输入一行字符,必须先用一个getline()

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
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
int n ;
map<string , vector<string> > books;
//map<char , vector<string> > query;
vector<string> queryWord;
int main()
{
cin>>n;
string ttt;
getline(cin , ttt);
int i , j;
for(i = 0 ; i < n ; ++i)
{
string str , id;
bool isF = true;
for(j = 0 ; j < 6 ; ++j)
{
if(isF)
{
getline(cin , str);
//cout<<str<<endl;
id = str;
isF = false;
}
else
{
getline(cin , str);
//cout<<str<<endl;
if(j == 3)//keyword 单独处理
{
string temp;
int k;
for(k = 0 ; k < str.length() ; ++k)
{
if(str[k] == ' ')
{
// cout<<temp<<endl;
books[temp].push_back(id);
temp = "";
continue;
}
temp += str[k];
}
//cout<<temp<<endl;
books[temp].push_back(id);
continue;
}
books[str].push_back(id);
}
}
}
int m;
cin>>m;
getline(cin , ttt);
string queryStr;
for(i = 0 ; i < m ; ++i)
{
getline(cin , queryStr);
queryWord.push_back(queryStr);
/*char ch = queryStr[0];
//cout<<queryStr.substr(queryStr.find(' ')+1 , queryStr.length())<<endl;
string q = queryStr.substr(queryStr.find(' ')+1 , queryStr.length());
cout<<queryStr<<endl;
int k ;
for(k = 0 ; k < books[q].size() ; ++k)
{
cout<<books[q][k]<<endl;
}*/
//query[ch].push_back(queryStr.substr(queryStr.find(' ')+1 , queryStr.length()));
}
for(i = 0 ; i < m ; ++i)
{
string qs =queryWord[i];
string q = qs.substr(qs.find(' ')+1 , qs.length());
cout<<qs<<endl;
int k ;
sort(books[q].begin() , books[q].end());
for(k = 0 ; k < books[q].size() ; ++k)
{
cout<<books[q][k]<<endl;
}
if(books[q].size() == 0)
{
cout<<"Not Found"<<endl;
}
}
return 0;
}

热评文章