Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5303 | Accepted: 3162 |
这一题相当得简单只要正反比较两次即可,运用队列表示正向的,用栈表示反向的
代码:
1 #include < stdio.h >
2 #include < queue >
3 #include < stack >
4 using namespace std;
5 int main()
6 {
7 int t,i,mark;
8 char s1[ 105 ],s2[ 105 ];
9
10 scanf( " %d " , & t);
11 while (t -- )
12 {
13 mark = 0 ;
14 scanf( " %s%s " ,s1,s2);
15 queue < char > qu;
16 stack < char > st;
17 for (i = 0 ;s2[i] != ' \0 ' ;i ++ )
18 {
19 st.push(s2[i]);
20 qu.push(s2[i]);
21 }
22 for (i = 0 ;s1[i] != ' \0 ' ;i ++ )
23 {
24 char x,y;
25 x = st.top();
26 y = qu.front();
27 if (x == s1[i])
28 st.pop();
29 if (st.empty())
30 {
31 mark = 1 ;
32 break ;
33 }
34 if (y == s1[i])
35 qu.pop();
36 if (qu.empty())
37 {
38 mark = 1 ;
39 break ;
40 }
41 }
42 if (mark)
43 printf( " YES\n " );
44 else
45 printf( " NO\n " );
46 }
47 return 0 ;
48 }
49