今天做的水题有点多,犹豫要不要发出来,不管了,明天再说……
想起大二下的时候数据结构为了一个栈的写费了多长的时间,现在用STL的格式简洁明快。所以说:不要重复造轮子。
简直要哭了。
随便写写吧:完整代码如下,一些小的感受也保存了起来,明天再好好练习:
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
//1、2、3表示的只是入栈的顺序,没有说什么时候会出来
int main(void)
{
int n;
int i,j,k=0;
int count=0;
char temp[1000];
int order[1000],target[1000];
while(cin>>n){
bool flag=true;
cin>>temp; //数组,string也可以
for(i=0;i<n;i++)
order[i]=temp[i]-48; //完成char数字向int型数字的转化
cin>>temp;
for(i=0;i<n;i++)
target[i]=temp[i]-48;
stack<int> s;
int A=0,B=0;
while(B<n){
if(!s.empty() && s.top()==target[B])
{
s.pop();
B++;
ans[k++]=1; //out
}
else if(A<n)
{
s.push(order[A]);
A++;
ans[k++]=0;
}
else {
flag=false;
break;
}
}
if(!flag) cout<<"no."<<endl;
else for(i=0;i<=k-1;k++)
if(ans[k]) cout<<"in"<<endl;
else cout<<"out"<<endl;
}
}