Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int tcase;
- string S, A;
- cin >> tcase;
- int caseNo = 0;
- while(tcase--) {
- cin >> S >> A;
- int n = (int)S.length();
- int m = (int)A.length();
- vector<vector<bool>> M(n + 1, vector<bool>(m + 1, false));
- M[0][0]=true;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- if(!M[i-1][j-1]) continue;
- if(S[i-1]=='*'){
- for(int k=0;k<4 && j + k <= m;k++) M[i][j+k]=true;
- M[i][j-1]=true;
- }
- if(A[j - 1] =='*'){
- for(int k=0;k<4 && i + k <= n;k++) M[i+k][j]=true;
- M[i-1][j]=true;
- }
- if(S[i - 1]==A[j - 1] ) M[i][j]=true;
- }
- }
- cout << "Case #" << ++caseNo << ": " << (M[n][m] ? "TRUE" : "FALSE") << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement