-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path123.cpp
59 lines (52 loc) · 1.63 KB
/
123.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
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
struct Title {
size_t idx;
std::string key, full;
};
bool sort_title(const Title &x, const Title &y)
{
auto size = x.key.size() > y.key.size() ? y.key.size() : x.key.size();
for (int i = 0; i < size; ++i) {
if (x.key[i] != y.key[i]) return x.key[i] < y.key[i];
}
return x.key.size() == y.key.size() ? x.idx < y.idx
: x.key.size() < y.key.size();
}
int main(void)
{
std::string buffer;
std::vector<std::string> keyword;
std::vector<Title> title;
while (1) {
getline(std::cin, buffer);
if (buffer == "::") break;
keyword.push_back(buffer);
}
size_t count = 0;
while (getline(std::cin, buffer)) {
std::transform(buffer.begin(), buffer.end(), buffer.begin(), ::tolower);
size_t i = 0, j;
do {
j = buffer.substr(i).find(' ');
auto sub = buffer.substr(i, j);
if (std::find(keyword.begin(), keyword.end(), sub) ==
keyword.end()) {
std::transform(sub.begin(), sub.end(), sub.begin(), ::toupper);
title.push_back({count * 10000 + i, sub, buffer});
for (int l = 0; l < sub.size(); ++l) {
title.back().full[i + l] = sub[l];
}
}
i += j + 1;
} while (j != std::string::npos);
++count;
}
std::sort(title.begin(), title.end(), sort_title);
for (const auto &t : title) {
std::cout << t.full << std::endl;
}
return 0;
}