-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathWSITES01.cpp
76 lines (68 loc) · 1.53 KB
/
WSITES01.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
// Code written by Monal
#include "bits/stdc++.h"
#include <stdio.h>
using namespace std;
#define li long int
#define in(a) cin>>a
#define out(a) cout<<a<<"\n"
#define pb(a) push_back(a)
#define forn(n) for (int i = 0; i < n; ++i)
vector < string > yes;
vector < string > no;
vector <string > answer;
template <typename Container>
bool LexCompare(const Container& a, const Container& b) {
return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
// Use that comparison function to sort a range:
template <typename ContainerIterator>
void sort_by_lexicographical_comapre(ContainerIterator beg, ContainerIterator end) {
sort(beg, end, LexCompare<typename ContainerIterator::value_type>);
}
string calculate(string check, vector<string> yes) {
for (int i = 1; i <= check.length(); ++i) {
int j;
string temp = check.substr(0,i);
for (j = 0; j < yes.size(); ++j) {
if (i > yes[j].length())
continue;
if (temp == yes[j].substr(0,i))
break;
}
if (j == yes.size())
return temp;
}
return "NO";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
in(n);
char ch;
string s;
forn(n) {
in(ch);
in(s);
if (ch == '+')
yes.pb(s);
else
no.pb(s);
}
forn(no.size()) {
string temp = calculate(no[i],yes);
if (temp != "NO")
answer.pb(temp);
}
if (answer.size() != no.size()) {
cout<<"-1";
return 0;
}
set<string> myset( answer.begin(), answer.end() );
answer.assign( myset.begin(), myset.end() );
out(answer.size());
forn(answer.size()) {
out(answer[i]);
}
return 0;
}