View Code
1
#include
<
iostream
>
2 #include < cstring >
3 using namespace std;
4 char a[ 505 ],b[ 505 ],c[ 1005 ];
5 int len,len1,len2,flag;
6 void solve( int i, int j, int k)
7 {
8 if (i == len && len1 == j && len2 == k) {flag = 1 ; return ;}
9 if (flag || i >= len || j > len1 || k > len2) return ;
10 if (j < len1 && c[i] == a[j]) solve(i + 1 ,j + 1 ,k);
11 if (k < len2 && c[i] == b[k]) solve(i + 1 ,j,k + 1 );
12 return ;
13 }
14 int main()
15 {
16 int t,d = 1 ;
17 cin >> t;
18 while (t -- )
19 {
20 cin >> a >> b >> c;
21 len1 = strlen(a);
22 len2 = strlen(b);
23 len = strlen(c);
24 int i = 0 ,j = 0 ,k = 0 ;
25 flag = 0 ;
26 if (a[ 0 ] != c[ 0 ] && b[ 0 ] != c[ 0 ]) flag = 0 ;
27 else if (a[len1 - 1 ] != c[len - 1 ] && b[len2 - 1 ] != c[len - 1 ]) flag = 0 ;
28 else
29 solve( 0 , 0 , 0 );
30 if (flag) cout << " Data set " << d << " : yes " << endl;
31 else cout << " Data set " << d << " : no " << endl;
32 d ++ ;
33 }
34 return 0 ;
35 }
2 #include < cstring >
3 using namespace std;
4 char a[ 505 ],b[ 505 ],c[ 1005 ];
5 int len,len1,len2,flag;
6 void solve( int i, int j, int k)
7 {
8 if (i == len && len1 == j && len2 == k) {flag = 1 ; return ;}
9 if (flag || i >= len || j > len1 || k > len2) return ;
10 if (j < len1 && c[i] == a[j]) solve(i + 1 ,j + 1 ,k);
11 if (k < len2 && c[i] == b[k]) solve(i + 1 ,j,k + 1 );
12 return ;
13 }
14 int main()
15 {
16 int t,d = 1 ;
17 cin >> t;
18 while (t -- )
19 {
20 cin >> a >> b >> c;
21 len1 = strlen(a);
22 len2 = strlen(b);
23 len = strlen(c);
24 int i = 0 ,j = 0 ,k = 0 ;
25 flag = 0 ;
26 if (a[ 0 ] != c[ 0 ] && b[ 0 ] != c[ 0 ]) flag = 0 ;
27 else if (a[len1 - 1 ] != c[len - 1 ] && b[len2 - 1 ] != c[len - 1 ]) flag = 0 ;
28 else
29 solve( 0 , 0 , 0 );
30 if (flag) cout << " Data set " << d << " : yes " << endl;
31 else cout << " Data set " << d << " : no " << endl;
32 d ++ ;
33 }
34 return 0 ;
35 }