ACM 威士忌部分答案
源代码在线查看: 1022 train problem i.cpp
/*
1022 Train Problem I
Time Limit : 1000 ms Memory Limit : 32768 K Output Limit : 1024 K
GUN C++
*/
#include
#include
using namespace std;
const int Max=100;
int Locate(char array[],char num,int low,int high)
{
for(; array[low]!=num && low if(array[low]!=num)
return -1;
else
return low;
}
int main()
{
int loc,n,i,j,step;
char order1[Max],order2[Max],station[10];
int run[Max];
int top,po1;
bool flag;
while(cin>>n)
{
cin>>order1;
cin>>order2;
memset(station,0,sizeof(station));
top=po1=step=0;
flag=true;
for(i=0;i {
loc=Locate(station,order2[i],0,top); //在车站的位置
if(loc {
loc=Locate(order1,order2[i],po1,n); //在进入队列的位置
if(loc { flag=false;break;}
else
{
for(; po1 {
station[top]=order1[po1];
run[step]=1;
}
po1=loc+1; // 出栈本元素
run[step++]=1;
run[step++]=0;
}//if
}
else
{
if(loc==top-1)
{
run[step++]=0;
top--;station[top]=0;
}
else
{ flag=false;break;}
}
}//for
if(flag)
{
cout for(i=0;i if(run[i])
cout else
cout }
else
cout cout }
return 0;
}