程序设计实习MOOC的程序设计与算法(二)测验汇总(2019春季) 013Zipper
程序员文章站
2022-05-08 23:49:56
...
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e2 + 1 ;
int dp[maxn][maxn];
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int N;
scanf("%d", &N);
int i, j, k;
for(k = 1; k <= N; k++){
string s[3];
int len[3];
for(i = 0; i < 3; i++){
cin >> s[i];
len[i] = s[i].size();
}
memset(dp, 0, sizeof(dp));
for(i = 0; i < len[0]; i++){
if(s[0][i] == s[2][i]) dp[i + 1][0] = 1;
else break;
}
for(i = 0; i < len[1]; i++){
if(s[1][i] == s[2][i]) dp[0][i + 1] = 1;
else break;
}
for(i = 1; i <= len[0]; i++){
for(j = 1; j <= len[1]; j++){
if(dp[i - 1][j] && s[0][i - 1] == s[2][i + j - 1]){
dp[i][j] = 1;
}
if(dp[i][j - 1] && s[1][j - 1] == s[2][i + j - 1]){
dp[i][j] = 1;
}
}
}
printf("Data set %d: ", k);
if(dp[len[0]][len[1]] == 1) printf("yes\n");
else printf("no\n");
}
return 0;
}