您的位置:首页 > 其它

奋战杭电ACM(DAY14)1022

2013-09-06 00:59 309 查看
这道题本身不难,直接栈的应用做就可以了;

学到了栈的新建,插入,删除,空判断等基本操作;

标记数组很新颖嘛~~~



Train Problem I

#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
int n;
string getin,getout;
while(cin >> n >> getin >> getout)
{
int *result = new int[n*2];
memset(result,0,sizeof(result));

int a=0;
int b=0;
int c=0;
int i;

stack<char> s;

while(b<n)
{
if(a<n && getin[a]==getout[b])
{
a++;
b++;
result[c]=1;
c+=2;
}
else if(!s.empty() && s.top()==getout[b])
{
s.pop();
c++;
b++;
}
else if(a<n && getin[a]!=getout[b])
{
s.push(getin[a]);
a++;
result[c]=1;
c++;
}
else
{
cout << "No." << endl;
goto end;
}
}
cout << "Yes." << endl;
for(i=0; i<n*2; i++)
{
if(result[i]==1)
cout << "in" << endl;
else
cout << "out" << endl;
}
end:cout << "FINISH" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: