Advertisement
mickypinata

SMMR-T119: Message

Jul 28th, 2021
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 2000;
  5.  
  6. char str[N + 2], tr[N + 2];
  7. bool dp[N + 1][N + 1];
  8.  
  9. int main(){
  10.  
  11.     int Q;
  12.     scanf(" %s%d", str + 1, &Q);
  13.     int len = strlen(str + 1);
  14.     while(Q--){
  15.         scanf(" %s", tr + 1);
  16.         int tlen = strlen(tr + 1);
  17.         dp[0][0] = true;
  18.         for(int i = 0; i <= len; ++i){
  19.             for(int j = 1; j <= tlen; ++j){
  20.                 if(tr[j] == '$'){
  21.                     bool ans = false;
  22.                     if(i != 0){
  23.                         ans |= dp[i - 1][j];
  24.                     }
  25.                     ans |= dp[i][j - 1];
  26.                     dp[i][j] = ans;
  27.                 } else if(tr[j] == '-'){
  28.                     dp[i][j] = i != 0 && dp[i - 1][j - 1];
  29.                 } else {
  30.                     dp[i][j] = i != 0 && tr[j] == str[i] && dp[i - 1][j - 1];
  31.                 }
  32.             }
  33.         }
  34.         if(dp[len][tlen]){
  35.             cout << "success\n";
  36.         } else {
  37.             cout << "fail\n";
  38.         }
  39.     }
  40.  
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement