-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathname2.cpp
46 lines (38 loc) · 829 Bytes
/
name2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <string.h>
char M[25001], W[25001];
int CanMarry(int len_m, int len_w, char M[], char W[])
{
int cm = 0; // current_match
int ret = -1;
for(int w=0;w<len_w;++w)
{
if(M[cm] == W[w])
{
cm++;
if(cm == len_m)
{
ret = 1;
break;
}
}
}
return ret;
}
int main(void)
{
int tc;
scanf("%d", &tc);
for(int t=0; t<tc; ++t)
{
scanf("%s %s\n", &M, &W);
int len_m = strlen(M);
int len_w = strlen(W);
int res1 = CanMarry(len_m, len_w, M, W);
int res2 = CanMarry(len_w, len_m, W, M);
int res = res1 > res2 ? res1 : res2;
if(res == 1) printf("YES\n");
if(res == -1) printf("NO\n");
}
return 0;
}