杭电1022Train Problem I



3 123 312
in
in
in
out
out
out
FINISH
No.
FINISH
Hint
For 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.".
思路:紫书上原题,题意是给你一个进站前的数列,判断这几个数能否通过类似入栈出栈的操作后得到题目所给的数列;
用栈来模拟就好。
ps:一定要注意输出格式!!!写完代码之后,愣是一直wa,开始是因为栈没清空,后又发现是输出格式不对!!!
血的教训,改了好半天!!!
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <string> #define PI acos((double)-1)
#define E exp(double(1))
#define N 1000000
using namespace std; int main (void)
{
int t,a,b,flag,c;
string s,e,code;
stack<int>sk;
while(scanf("%d",&t) == && t)
{
cin>>s>>e;
flag=;
a=b=c=;
while(b<t)
{
if(s[a] == e[b])
{
a++;b++;
code[c++]=;
code[c++]=;
}
else if(!sk.empty() && e[b] == sk.top())
{
sk.pop();b++;
code[c++]=;
}
else if(a < t)
{
sk.push(s[a++]);
code[c++]=;
}
else
{
flag = ;
break;
}
}
if(flag)
{
cout<<"Yes."<<endl;
for(int i = ;i< *t;i++)
if(code[i])
cout<<"in"<<endl;
else
cout<<"out"<<endl;
}
else
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
while(!sk.empty())
sk.pop();
}
return ;
}
杭电1022Train Problem I的更多相关文章
- 杭电1023Train Problem II
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目: Train Problem II Time Limit: 2000/1000 MS (Jav ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评
最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- 杭电OJ——1198 Farm Irrigation (并查集)
畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- HDU-2500 做一个正气的杭电人
http://acm.hdu.edu.cn/showproblem.php?pid=2500 做一个正气的杭电人 Time Limit: 1000/1000 MS (Java/Others) M ...
- 杭电 2047 阿牛的EOF牛肉串 (递推)
阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 做一个正气的杭电人--hdu2500
做一个正气的杭电人 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- C语言 函数指针二(正向调用)
//函数指针做函数参数 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<Wi ...
- Python 数据库连接池
python编程中可以使用pymysql进行数据库连接及增删改查操作,但每次连接mysql请求时,都是独立的去请求访问,比较浪费资源,而且访问数量达到一定数量时,对mysql的性能会产生较大的影响.因 ...
- 第二百三十节,jQuery EasyUI,后台管理界面---后台管理
jQuery EasyUI,后台管理界面---后台管理 一,admin.php,后台管理界面 <?php session_start(); if (!isset($_SESSION['admin ...
- C#反射实例(一) 利用反射使用类库
在网上查找了不少的资料,可以说大同小异,概念性的东西网上一搜一堆,今天把反射的东西整理了一下,供大家使用,我保证我这里是最全面的东西,当然也是基础的东西,在学好了这一切的基础上,大家可以学习反射的具体 ...
- Python相对完美的URL拼接函数
首先说下什么叫URL拼接,我们有这么一个HTML片段: <a href="../../a.html">click me</a> 做为一只辛苦的爬虫,我们 ...
- matlab中图片数据类型转换uint8与double
matlab中处理图像像素点数据: img1=double(imread('lenna.bmp')); matlab中imshow图片,要先转换成uint8: subplot(1,2,1),imsho ...
- java获取系统时区
//Calendar cal = Calendar.getInstance(); //TimeZone timeZone = cal.getTimeZone(); TimeZone timeZone ...
- 你一定喜欢看的 Webpack 2.× 入门实战
from:https://www.jianshu.com/p/b83a251d53db?utm_campaign=maleskine&utm_content=note&utm_medi ...
- Android UI开发第三十六篇——使用Volley加载图片列表
Android开发者可能会使用Universal Image Loader或者Square`s newer Picasso这些第三方的库去处理图片的加载,那么Volley是怎么加载图片列表的呢,这一篇 ...
- oracle用于判断时间条件为当天的写法(当前日期加一天)
trunc(sysdate + 1, 'dd')为当前日期加一天: 来自: and wf.start_time between sysdate and trunc(sysdate + 1, 'dd') ...