zoukankan      html  css  js  c++  java
  • hdu1022 Train Problem I

    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         else
    41         {
    42             cout<<"Yes."<<endl;
    43             for(i=0;i<k;i++)
    44             {
    45                 if(result[i])
    46                 cout<<"in"<<endl;
    47                 else
    48                 cout<<"out"<<endl;
    49             }
    50         }
    51         cout<<"FINISH"<<endl;
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    关于全景漫游
    webgl圈中物体
    css3の极限
    reactjs弹幕视频播放
    数值积分I
    显出你的h5逼格
    奇葩のbeforeunload
    面试问题搜集及解析
    TCP拥塞控制(滑动窗口机制)
    如何使CPU占用率为50%
  • 原文地址:https://www.cnblogs.com/xuesen1995/p/4491190.html
Copyright © 2011-2022 走看看