Advertisement
Kaidul

Untitled

Mar 5th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     freopen("input.txt", "r", stdin);
  7.     freopen("output.txt", "w", stdout);
  8.     int tcase;
  9.     string S, A;
  10.     cin >> tcase;
  11.     int caseNo = 0;
  12.     while(tcase--) {
  13.         cin >> S >> A;
  14.         int n = (int)S.length();
  15.         int m = (int)A.length();
  16.         vector<vector<bool>> M(n + 1, vector<bool>(m + 1, false));
  17.         M[0][0]=true;
  18.  
  19.         for(int i=1;i<=n;i++){
  20.  
  21.             for(int j=1;j<=m;j++){
  22.  
  23.                   if(!M[i-1][j-1]) continue;
  24.  
  25.                   if(S[i-1]=='*'){
  26.  
  27.                         for(int k=0;k<4 && j + k <= m;k++) M[i][j+k]=true;
  28.  
  29.                         M[i][j-1]=true;
  30.                   }
  31.  
  32.                   if(A[j - 1] =='*'){
  33.  
  34.                       for(int k=0;k<4 && i + k <= n;k++) M[i+k][j]=true;
  35.  
  36.                       M[i-1][j]=true;
  37.                   }
  38.  
  39.                   if(S[i - 1]==A[j - 1] ) M[i][j]=true;
  40.             }
  41.  
  42.         }
  43.         cout << "Case #" << ++caseNo << ": " << (M[n][m] ? "TRUE" : "FALSE") << endl;
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement