Guest User

Untitled

a guest
Mar 15th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string S;
  9.     int n;
  10.     cin >> S;
  11.     cin >> n;
  12.     auto L = vector<string>(n);
  13.     for (int i = 0; i < n; ++i) cin >> L[i];
  14.     auto dp = vector<bool>(S.size() + 1, false);
  15.     dp[0] = true;
  16.     for (int i = 0; i < S.size(); ++i) {
  17.         for (int j = 0; j < L.size(); ++j) {
  18.             if (i + 1 < L[j].size()) continue;
  19.             bool match = true;
  20.             for (int k = 0; k < L[j].size(); ++k) {
  21.                 if (S[i - L[j].size() + k + 1] != L[j][k]) {
  22.                     match = false;
  23.                     break;
  24.                 }
  25.             }
  26.             if (match && dp[i - L[j].size() + 1]) {
  27.                 dp[i + 1] = true;
  28.                 break;
  29.             }
  30.         }
  31.     }
  32.     cout << dp[S.size()] << endl;
  33. };
Add Comment
Please, Sign In to add comment