题目是栈的模拟进出。

先用数组来模拟一下栈的指针移动。

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
#include <stdio.h>
#include <stdlib.h>

int main(){
//freopen("in.txt","r",stdin);
int a[1000];
char c[1000];
char s1[1000],s2[1000];
int n;
//scanf("%d",&n);
while(scanf("%d %s%s",&n,s1,s2)!=EOF){
int m = 0,j = 0,k = 0;
for(int i = 0; i < n;i++){
a[j++] = 1;
c[k++] = s1[i];
while(c[k-1] == s2[m]&& k >= 0){
a[j++] = -1;
m++;
k--;
}
}
if(k <= 0){
printf("Yes.\n");
for(int i = 0;i < j;i++){
if(a[i] == 1)
printf("in\n");
else if(a[i] == -1) printf("out\n");
}
}else
printf("No.\n");
printf("FINISH\n");
}
return 0;
}