难度:2
算法:模拟一个栈
大家只要了解一下栈的实现就能很好的模拟出这道提
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n , sta[100] , od[100] , cnt;
char c1[100] , c2[100];
bool check() {
cnt = 0;
int i = 0 , j = 0 , s = 0;
while(j < n) {
if(c1[i] == c2[j]) {
od[cnt++] = 1;
od[cnt++] = 0;
i++; j++;
}
else if(s > 0 && sta[s-1] == c2[j]) {
od[cnt++] = 0;
s--;
j++;
}
else if(i < n) {
od[cnt++] = 1;
sta[s++] = c1[i];
i++;
}
else return false;
}
return true;
}
int main() {
while(~scanf("%d%s%s" , &n , c1 , c2)) {
if(!check()) {
puts("No.");
puts("FINISH");
}
else {
puts("Yes.");
for(int i=0;i<cnt;i++) {
if(od[i] == 1) puts("in");
else puts("out");
}
puts("FINISH");
}
}
return 0;
}