HDU 1022 Train Problem I
来源:互联网 发布:残棋破解软件 编辑:程序博客网 时间:2024/06/05 22:38
这题我的想法使用栈的思想去解决的,就是根据进站的序列加入栈中,若和出站最开始的序号相同,则出栈;然后继续进行此操作,和下一个出站的火车序号相比较。这样操作完后看看栈是否为空,就可以判断了。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<stack>#include<queue>using namespace std;int main(){ char s1[10],s2[10],s3[20][5]; int n; while(scanf("%d%s%s",&n,s1,s2)!=EOF) { stack<char> s; int top2=0,top3=0; for(int i=0;i<n;i++) { s.push(s1[i]); strcpy(s3[top3++],"in");//此处就是我的思想 while(!s.empty()) { char a=s.top(); if(a==s2[top2]) { strcpy(s3[top3++],"out"); s.pop(); top2++; } else break; } } if(s.empty()) { printf("Yes.\n"); for(int i=0;i<top3;i++) printf("%s\n",s3[i]); } else printf("No.\n"); printf("FINISH\n"); } return 0;}
0 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
- hdu 1022 Train Problem I
- hdu-Train Problem I-1022
- 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 1022Train Problem I
- Android wifi框架
- python编码转换__&__UNICODE,GBK,UTF-8区别
- Android setColorFilter 滤镜效果
- Android中Context
- C10K 问题引发的技术变革
- HDU 1022 Train Problem I
- Java_语法基础_自动装箱拆箱及易考细节
- 08-2. The World's Richest
- 253 - Cube painting
- Xcode 6 SVN客户端初步使用记录
- android-code-调节屏幕亮度
- 【Machine Learning】音特征提取技巧
- 低耦合,高内聚真的好吗?
- KMP