compile error两遍。
原因:没考虑栈为空的情况
代码:
#include<cstdio> #include<iostream> #include<stack> #include<string> #include<cstring> using namespace std; int n; char s1[11],s2[12]; stack<char>q; string ans; int main() { while(~scanf("%d%s%s",&n,s1,s2)) { int flag=1; while(!q.empty()) q.pop(); ans.clear(); int it=-1; for(int i=0; i<n;) { if(q.empty()) { q.push(s1[++it]); ans+="in "; } else { if(q.top()==s2[i]) { q.pop(); ans+="out "; i++; } else { if(it==n-1) { //cout<<"2 "; flag=0; break; } else { //cout<<"3 "; ans+="in "; q.push(s1[++it]); } } } } if(flag) { cout<<"Yes."<<endl; cout<<ans; cout<<"FINISH "; } else { cout<<"No. FINISH "; } } return 0; }