标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32387 Accepted Submission(s): 12221
/* 按照某种顺序出栈,只能有一种方式(因为栈内的元素是不重复的,要是想另一种出栈方式肯等陷入死循环) */ #include<bits/stdc++.h> using namespace std; vector<string> cur;//用来存放可能方式 int n; struct node { string s1,s2; node(string x1,string x2){s1=x1;s2=x2;} bool solve() { if(s1.size()!=s2.size()) return false; stack<char> s; int i=0,j=0; while(i<s1.size()||j<s2.size()) { if(!s.empty()&&j<s2.size()&&s.top()==s2[j]) { cur.push_back("out"); s.pop(); j++; } else { if(i==s1.size()) { //cout<<"end="<<s1[i-1]<<endl; return false; } s.push(s1[i++]); cur.push_back("in"); } } return true; } }; int main() { //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin); string s1,s2; while(scanf("%d",&n)!=EOF) { cur.clear(); cin>>s1>>s2; //cout<<n<<" "<<s1<<" "<<s2<<endl; node fr(s1,s2); if(!fr.solve()||n>9) { printf("No.\n"); printf("FINISH\n"); continue; } else { printf("Yes.\n"); for(int i=0;i<cur.size();i++) cout<<cur[i]<<endl; printf("FINISH\n"); } } }
标签:
原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/5936139.html