-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPotW3.cpp
More file actions
42 lines (35 loc) · 923 Bytes
/
PotW3.cpp
File metadata and controls
42 lines (35 loc) · 923 Bytes
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
#include <iostream>
#include <set>
#include <string>
#include <vector>
bool valid_sentence(const std::set<std::string>& dictionary, const std::string& line, int pos) {
bool ret;
std::string word;
for (unsigned i = pos; i != line.size(); ++i) {
word += line[i];
if (dictionary.find(word) != dictionary.end()) {
ret = valid_sentence(dictionary, line, i+1);
if (ret)
return true;
}
}
return dictionary.find(word) != dictionary.end();
}
int main() {
int n;
std::cin >> n;
std::set<std::string> dictionary;
for (int i = 0; i != n; ++i) {
std::string s;
std::cin >> s;
dictionary.insert(s);
}
int m;
std::cin >> m;
for (int i = 0; i != m; ++i) {
std::string s;
std::cin >> s;
std::cout << valid_sentence(dictionary, s, 0) << std::endl;
}
return 0;
}