HDU1022 - Train Problem I (模拟)
来源:互联网 发布:多益网络成都加班 编辑:程序博客网 时间:2024/06/04 19:50
题目链接
- 思路
- 代码
思路
按照他所说的规则,模拟一遍,用一个栈作为媒介。
代码
#include <cstdio>#include <vector>#include <string>#include <stack>using namespace std;char A[10];char B[10];int main(){ int len, a, b; vector<string> output; stack<char> temp; while(scanf("%d", &len)==1) { scanf("%s%s", B, A); // 初始化数据 a = b = 0; output.clear(); while(!temp.empty()) temp.pop(); bool flag = true; while(a<len) { // 从 B 到 A if(B[b]==A[a]) { a++; b++; output.push_back("in"); output.push_back("out"); } // 从栈到 A else if(!temp.empty() && temp.top()==A[a]) { temp.pop(); a++; output.push_back("out"); } // 从 B 到栈 else if(b<len) { temp.push(B[b]); output.push_back("in"); b++; } // 失败退出 else { flag = false; break; } } if(flag) { printf("Yes.\n"); for(int i=0; i<output.size(); i++) printf("%s\n", output[i].c_str()); printf("FINISH\n"); } else { printf("No.\n"); printf("FINISH\n"); } } return 0;}
0 0
- HDU1022 - Train Problem I (模拟)
- hdu1022 栈的模拟(Train Problem I)
- HDU1022 Train Problem I
- HDU1022 Train Problem I
- HDU1022:Train Problem I
- HDU1022--Train Problem I
- hdu1022-Train Problem I
- HDU1022 Train Problem I
- hdu1022 Train Problem I
- hdu1022 Train Problem I
- HDU1022 Train Problem I
- HDU1022 Train Problem I
- hdu1022 Train Problem I
- hdu1022-Train Problem I
- hdu1022 - Train Problem I
- hdu1022 Train Problem I
- HDU1022--Train Problem I HDU(136)
- Train Problem I--hdu1022(栈)
- MQTTKit即时通讯使用
- JS设计模式——单例模式
- Android ListView 基础入门 简介以及深入优化
- 寻根究底,探讨 chi -square特征词选择方法后面的数学支持
- Linux chmod命令详解
- HDU1022 - Train Problem I (模拟)
- JS设计模式——构造函数模式
- 冒泡排序
- JAVA读写文件,如何避免中文乱码
- EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP
- 缓冲技术
- Spring+JDBC组合开发
- 关于squirrel的那些事
- 常见内存泄漏原因