不是队列,是栈。
重剑无锋,大巧不工
#include<stdio.h> #define MAX 24 char stack[MAX]; char in[MAX], out[MAX]; char solve[MAX]; int n, sn; int cal() { int i, sp = 0, ip = 0; char t; for(sn = 0, i = 0; i < n; i++) { t = out[i]; while(sp <= 0 || (stack[sp - 1] != t && ip < n)) { stack[sp++] = in[ip++]; solve[sn++] = 1; } if(stack[--sp] != t) return 0; solve[sn++] = 0; } return 1; } void output() { int i; if(cal()) { printf("Yes.\n"); for(i = 0; i < sn; printf("%s\n", solve[i++] ? "in" : "out")); } else printf("No.\n"); printf("FINISH\n"); } int main() { while(scanf("%d %s %s", &n, in, out) != EOF) output(); return 0; }