hdu1022 Train Problem I
来源:互联网 发布:淘宝助理韵达模板下载 编辑:程序博客网 时间:2024/06/01 07:51
http://acm.hdu.edu.cn/showproblem.php?pid=1022
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #include<string.h> 5 #include<stdlib.h> 6 #include<stack> 7 using namespace std; 8 const int N=100; 9 10 int main()11 {12 //freopen("in.txt","r",stdin);13 stack<char>s;14 int n,result[N];15 char s1[N],s2[N];16 int i,j,k;17 while(cin>>n>>s1>>s2)18 {19 i=0;j=0;k=1;20 s.push(s1[i]);21 result[0]=1;22 while(i<n&&j<n)23 {24 if(s.size() && s.top()==s2[j])//如果栈取元素和s2当前元素相同,弹栈25 {26 j++;27 s.pop();28 result[k++]=0;29 }30 else//如果不相同,继续讲s1后一个元素压栈31 {32 if(i==n)33 break;34 s.push(s1[++i]);35 result[k++]=1;36 }37 }38 if(i==n)//如果i==n代表找不到s2中的当前元素39 cout<<"No."<<endl;40 else41 {42 cout<<"Yes."<<endl;43 for(i=0;i<k;i++)44 {45 if(result[i])46 cout<<"in"<<endl;47 else48 cout<<"out"<<endl;49 }50 }51 cout<<"FINISH"<<endl;52 }53 return 0;54 }
阅读全文
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
- HDU1022--Train Problem I HDU(136)
- 简单~音乐播放器
- hdu2717 Catch That Cow
- hdu1020 Encoding
- hdu1021 Fibonacci Again
- 1015. 德才论
- hdu1022 Train Problem I
- Boring隧道掘进机完成首段挖掘_离未来交通还有多远?
- hdu1031 Design T-Shirt
- hdu2010
- hdu2011
- 使用dubbo+zookeper实现服务调用与使用webservice对比
- hdu2012
- POSTGRESQL 存储过程实战
- hdu2013