做题思路必须很清晰啊....可以用数组存储in或out来着,第一次C++用string啊,效果还行
Problem : 1022 ( Train Problem I ) Judge Status : Accepted
RunId : 10418893 Language : C++ Author : mnmlist
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#include<iostream>
#include<string>
#include<stack>
using namespace std;
string isRight(int x,int *a,int *b);
int main()
{
int x,y,z;
int a[10],b[10];
while(cin>>x>>y>>z)
{
string str="";
for(int l=x;l>0;l--)
{
a[l]=y%10;y/=10;
b[l]=z%10;z/=10;
}
str=isRight(x,a,b);
cout<<str;
}
return 0;
}
string isRight(int x,int *a,int *b)
{
string str="";
stack<int>st;
int i=1,j=1;
while(i<2*x)
{
if(i<=x)
{
st.push(a[i]);
str+="in\n";
}
while(j<=x&&!st.empty()&&st.top()==b[j])
{
st.pop();
str+="out\n";
j++;
}
i++;
}
if(st.empty())
str="Yes.\n"+str;
else
str="No.\n";
str+="FINISH\n";
return str;
}