-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa123new.cpp
96 lines (90 loc) · 2.33 KB
/
UVa123new.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
#include<bits/stdc++.h>
using namespace std;
vector<string> split(string str)
{
int j;
vector<string> ans;
string tmp = "";
for(int i = 0 ;i < str.length(); i++)
{
if(str[i] != ' ')
tmp += str[i];
else
{
for(j = 0; j < tmp.length(); j++)
tmp[j] = tolower(tmp[j]);
ans.push_back(tmp);
tmp = "";
}
}
for(j = 0; j < tmp.length(); j++)
tmp[j] = tolower(tmp[j]);
ans.push_back(tmp);
return ans;
}
map<string,int> findword(vector<vector<string> > title,map<string,int> mp)
{
map<string,int> ans;
for(int i = 0 ;i < title.size(); i++)
for(int j = 0 ;j < title[i].size(); j++)
{
map<string,int>::iterator iter = mp.find(title[i][j]);
map<string,int>::iterator it = ans.find(title[i][j]);
if(iter == mp.end())
{
if(it != mp.end())
ans.insert(pair<string,int>(title[i][j],1));
else
(*iter).second++;
}
}
return ans;
}
void print(vector<string> line,int j)
{
vector<string> ans = line;
for(int k = 0; k < ans[j].length(); k++)
ans[j][k] = toupper(ans[j][k]);
for(int i = 0; i < ans.size()-1; i++)
cout<<ans[i]<<" ";
cout<<ans[ans.size()-1]<<endl;
}
void search(map<string,int> key,vector<vector<string> > title)
{
map<string,int>::iterator iter = key.begin();
while(iter != key.end())
{
for(int i = 0; i < title.size(); i++)
for(int j = 0; j < title[i].size(); j++)
if(title[i][j] == (*iter).first)
{
print(title[i],j);
(*iter).second--;
}
iter++;
}
}
int main()
{
map<string,int> pre;
string tmp;
while(cin>>tmp)
{
if(tmp == "::")
break;
pre.insert(pair<string,int>(tmp,1));
}
vector<vector<string> > title;
map<string,int> keyword;
while(getline(cin,tmp))
title.push_back(split(tmp));
title.erase(title.begin());
keyword = findword(title,pre);
search(keyword,title);
/*for(int i = 0; i < title.size(); i++)
{
for(int j = 0; j < title[i].size(); j++)
cout<<title[i][j]<<" ";
cout<<endl;
}*/
}