奋战杭电ACM(DAY14)1022
2013-09-06 00:59
309 查看
这道题本身不难,直接栈的应用做就可以了;
学到了栈的新建,插入,删除,空判断等基本操作;
标记数组很新颖嘛~~~
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
学到了栈的新建,插入,删除,空判断等基本操作;
标记数组很新颖嘛~~~
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
Train Problem I
#include <iostream> #include <string> #include <stack> using namespace std; int main() { int n; string getin,getout; while(cin >> n >> getin >> getout) { int *result = new int[n*2]; memset(result,0,sizeof(result)); int a=0; int b=0; int c=0; int i; stack<char> s; while(b<n) { if(a<n && getin[a]==getout[b]) { a++; b++; result[c]=1; c+=2; } else if(!s.empty() && s.top()==getout[b]) { s.pop(); c++; b++; } else if(a<n && getin[a]!=getout[b]) { s.push(getin[a]); a++; result[c]=1; c++; } else { cout << "No." << endl; goto end; } } cout << "Yes." << endl; for(i=0; i<n*2; i++) { if(result[i]==1) cout << "in" << endl; else cout << "out" << endl; } end:cout << "FINISH" << endl; } return 0; }
相关文章推荐
- 奋战杭电ACM(DAY5)1008
- 奋战杭电ACM(DAY11)1017
- 【ACM】杭电1022:Train Problem I
- 奋战杭电ACM(DAY5)1008
- 奋战杭电ACM(DAY11)1017
- Java 杭电ACM Train Problem I 1022
- 【ACM】杭电1022:Train Problem I
- 奋战杭电ACM(DAY12)1018
- 杭电ACM 1022 Train Problem I
- 奋战杭电ACM(DAY10)1015
- 奋战杭电ACM(DAY3)1004
- 奋战杭电ACM(DAY10)1015
- 奋战杭电ACM(DAY5)1012
- 奋战杭电ACM(DAY1)
- 奋战杭电ACM(DAY5)1012
- 奋战杭电ACM(DAY15)1034
- 杭电ACM 1022--Train Problem
- 奋战杭电ACM(DAY6)1010
- 奋战杭电ACM(DAY12)1019
- 杭电acm 1022题