-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11062.cpp
79 lines (64 loc) · 1.72 KB
/
11062.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
// iagorrr ;)
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
set<string> solve(string f){
stringstream is {f};
string t;
set<string> vans;
while(is >> t){
deque<char> dq{t.begin(), t.end()};
// remove non letters.
while(!dq.empty() and !isalpha(dq.back()) and dq.back() != '-') dq.pop_back();
while(!dq.empty() and !isalpha(dq.front()) and dq.front() != '-') dq.pop_front();
string ans;
while(!dq.empty()){
if(!isalpha(dq.front()) and dq.front() != '-'){
// to lower bound.
for(auto &x : ans)
x = (char)tolower(x);
if(!ans.empty() and ans != "\n") vans.insert(ans);
dq.pop_front();
ans.clear();
continue;
}
ans.push_back(dq.front());
dq.pop_front();
}
// to lower bound.
for(auto &x : ans)
x = (char)tolower(x);
if(!ans.empty() and ans != "\n"){
vans.insert(ans);
}
}
return vans;
}
int main(){
fastio
string l;
string f;
getline(cin, l);
f += l;
while(getline(cin, l)){
if(f.back() == '-'){
f.pop_back();
f += l;
}
else{
f+= ' ' + l;
}
}
// cout << f << '\n';
set<string> ans = solve(f);
vector<string> finalans;
for(auto x : ans)
finalans.push_back(x);
for(int i = 0; i < (int)finalans.size(); ++i)
cout << finalans[i] << '\n';
return 0;
}
// AC.