栈之火车进站和出站
来源:互联网 发布:手机数据恢复精灵下载 编辑:程序博客网 时间:2024/04/29 16:44
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stack>
using namespace std;
int main(void)
{
stack<char>s1;
stack<char>s2;
int n,i,j,t,a[1000];
char c[100010],d[100010];
while(scanf("%d",&n)!=EOF)
{j=0;
scanf("%s",c);
scanf("%s",d);
for(i=n-1;i>=0;i--)
s1.push(d[i]);
for(i=0;i<n;i++)
{
s2.push(c[i]);
a[j++]=1;
while(!s2.empty()&&s1.top()==s2.top())
{
s1.pop();
s2.pop();
a[j++]=0;
}
}
if(s1.empty()&&s2.empty())
{
printf("Yes.\n");
for(i=0;i<2*n;i++)
{
if(a[i]==1) printf("in\n");
else printf("out\n");
}
}
else printf("No.\n");
printf("FINISH\n");
}
return 0;
} 答案错误
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stack>
using namespace std;
int main(void)
{
stack<char>s1;
stack<char>s2;
int n,i,j,t,a[1000];
char c[100010],d[100010];
while(scanf("%d",&n)!=EOF)
{j=0;
scanf("%s",c);
scanf("%s",d);
for(i=n-1;i>=0;i--)
s1.push(d[i]);
for(i=0;i<n;i++)
{
s2.push(c[i]);
a[j++]=1;
while(!s2.empty()&&s1.top()==s2.top())
{
s1.pop();
s2.pop();
a[j++]=0;
}
}
if(s1.empty()&&s2.empty())
{
printf("Yes.\n");
for(i=0;i<2*n;i++)
{
if(a[i]==1) printf("in\n");
else printf("out\n");
}
}
else
{
printf("No.\n");
while(!s1.empty())
s1.pop(); 如果不能实现 ,那也就是说两个栈没有清空 ,必须清空才能继续下一个实例;
while(!s2.empty())
s2.pop();
}
printf("FINISH\n");
}
return 0;
}
- 栈之火车进站和出站
- 火车进站出站
- 火车进站出站问题
- 火车进站出站问题
- 用栈的思想分析火车进站出站问题
- 栈的应用——火车进站出站问题
- HDOJ acm 1022 火车进站出站(栈系列)
- 火车出站 模拟栈
- 杭电OJ1022~火车进站出站&南阳OJ~括号配对
- 火车进站(栈)
- 火车进站调用栈
- 华为oj之火车出站
- 栈,汽车进站出站:poj 1363 rails
- 火车出站
- 火车出站
- hdoj1022火车进站(栈)
- 【栈】华为OJ:火车进站
- 火车进站
- 数据迁移:从sql2008到oracle 10g
- iOS error no visible @interface for '***' declares the selector '***
- c语言中数组名a和&a详细介绍
- nc studio编译器编译大量错误问题解决
- 交换二维数组的两行
- 栈之火车进站和出站
- C中static的作用(精辟分析)
- beginUpdates和endUpdates-实现UITableView的动画块
- 第几天
- 统计C语言合法字符
- Android中文API——EditText
- 关于Viewpager中的Fragment的生命周期
- 牛顿迭代法求方程的根
- 不要62