【栈】hdu 1022 Train Problem I(外:poj 1383 Rails)
2013-10-27 20:38
495 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1022
http://poj.org/problem?id=1363
#include<iostream> #include<cstdio> #include<stack> using namespace std; int main() { stack<char>s1; char a[20],b[20]; int flag[25],n,i,j,k; while(cin>>n) { cin>>a>>b; while(!s1.empty()) s1.pop(); j=k=0; for(i=0;i<n;i++) { s1.push(a[i]); flag[j++]=1; while(!s1.empty()&&b[k]==s1.top()) { s1.pop(); k++; flag[j++]=2; } } if(s1.empty()) { cout<<"Yes."<<endl; for(i=0;i<j;i++) { if(flag[i]==1) cout<<"in"<<endl; else if(flag[i]==2) cout<<"out"<<endl; } } else cout<<"No."<<endl; cout<<"FINISH"<<endl; } return 0; }
http://poj.org/problem?id=1363
#include<iostream> #include<stack> using namespace std; int main() { stack<int>s1; int a[1001],m,n,i,kk; while(cin>>n&&n) { while(cin>>m&&m) { a[0]=m; kk=0; for(i=1;i<n;i++) cin>>a[i]; for(i=1;i<=n;i++) { s1.push(i); while(!s1.empty()&&s1.top()==a[kk]) {s1.pop();kk++;} } if(s1.empty()) cout<<"Yes"<<endl; else cout<<"No"<<endl; while(!s1.empty()) s1.pop(); } cout<<endl; } return 0; }
相关文章推荐
- public static void main(String[] args)中String[] args的作用
- Codeforces Round #208 (Div. 2) C. Dima and Containers
- sleep()、wait()、yield()、join()方法 解析
- 【转】将air 打包成绿色版exe
- Rails 3.x launcher script was found instead of Rails 4.x one.
- xcode编译时候出现clang: error: linker command failed with exit code 1 (use -v to see invocation)的解决方法
- Vmware10下安装Mac OS X Mountain Lion(10.8.5)
- 语音训练系统ant4 sphinxtrain
- RAII:互斥量
- [转]smail语法 详解
- Railscasts #2 Dynamic find_by Methods 动态find_by方法
- Kaitou Kid - The Phantom Thief (1) 第三次周赛
- Chinese remainder theorem again(hdu1788中国剩余定理)
- Raising Modulo Numbers(poj1995快速模运算)
- ubuntu10安装ideaiu12出现错误解决
- paip. 提升性能---hibernate的缓存使用 总结
- paip. 提升性能---hibernate的缓存使用 总结
- paip.解决access出现 -2147467259 无效的参数量
- paip.解决access出现 -2147467259 无效的参数量
- ognl.MethodFailedException: Method "setPic" failed for object com.employment.action.NewsAction@aac66