Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<string> dict;
- int main() {
- string src;
- cin >> src;
- int n;
- cin >> n;
- dict.resize(n);
- for (int i = 0; i < n; ++i) {
- cin >> dict[i];
- }
- bool is_word_found = true;
- int l = 0;
- int r = dict.size();
- for (int i = 0; i < src.size(); ++i) {
- bool is_letter_found = false;
- for (int j = l; j < r; ++j) {
- if (i < dict[j].size()) {
- if (src[i] < dict[j][i])
- continue;
- if (src[i] == dict[j][i] && !is_letter_found) {
- is_letter_found = true;
- l = j;
- }
- if (src[i] > dict[j][i]) {
- r = j;
- }
- }
- }
- if (is_letter_found) {
- is_word_found = false;
- break;
- }
- }
- if (is_word_found)
- cout << "YES" << endl;
- else
- cout << "NO" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement