Hdu 1022 Train Problem I (栈的简单应用)
来源:互联网 发布:雷霆主持人音效软件 编辑:程序博客网 时间:2024/05/21 18:33
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 36459 Accepted Submission(s): 13747
3 123 3213 123 312
Yes.inininoutoutoutFINISHNo.FINISHFor the first Sample Input, we let train 1 get in, then train 2 and train 3.So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.Now we can let train 3 leave.But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.So we output "No.".HintHint
#include<stdio.h>
#include<stack>
using namespace std;
int main()
{
int n,i,k,c[3005],t;
char a[1005], b[1005];
while (~scanf("%d%", &n)){
stack<char>q;
scanf("%s%s", a, b);
k = t = 0;
for (i = 0; i < n; i++){
q.push(a[i]);
c[t++] = 1;
while (!q.empty()){
char x = q.top();
if (x == b[k]){
c[t++] = 2;
k++;
q.pop();
}
else
break;
}
}
if (!q.empty())
printf("No.\nFINISH\n");
else{
printf("Yes.\n");
for (i = 0; i < t; i++)
if (c[i] == 1)
printf("in\n");
else
printf("out\n");
printf("FINISH\n");
}
}
return 0;
}
- hdu 1022 Train Problem I (栈的简单应用)
- Hdu 1022 Train Problem I (栈的简单应用)
- HDU 1022 Train Problem I(栈的简单应用)
- hdu-1022 Train Problem I (栈的简单应用)
- hdu 1022 Train Problem I(栈的应用。。。)
- hdu 1022 Train Problem I(栈的应用)
- HDU 1022 Train Problem I(栈的应用)
- hdu 1022 Train Problem I (栈的应用)
- HDU.1022 Train Problem I【栈的简单应用】(3.14)
- hdu Train Problem I(栈的简单应用)
- hdu 1022 Train Problem I(栈的应用+STL)
- hdu 1022 Train Problem I (栈的应用)
- HDU 1022:Train Problem I(堆栈的基本应用)
- HDU 1022 Train Problem I 简单的栈
- 1022 Train Problem I 栈的简单应用
- hdoj1022 Train Problem I(栈的简单应用)
- hdu 1022 Train Problem I(简单模拟+栈)
- hdu 1022 Train Problem I(栈)
- EXE;DLL;LIB学习心得
- 学习maven & SVN的使用——入职第2天工作总结
- C++ 内联函数与宏
- 计算矩阵的行列和
- HTTP请求的header头解析
- Hdu 1022 Train Problem I (栈的简单应用)
- 【数据结构】二叉树前中后序遍历、层序遍历(递归实现)
- Scala入门到精通——第二十四节 高级类型 (三)
- 初窥Maven
- python新手入门(一)
- IntelliJ IDEA 2017 汉化
- Uva 10026 Shoemaker's Problem
- 08_旋转数组的最小数字
- int 和 integer 的区别