zoukankan      html  css  js  c++  java
  • hdu--1022--Train Problem I

    题目链接

     1 #include <iostream> 
     2 #include <stack>
     3 using namespace std;
     4 int main() {
     5     int n;
     6     while (cin>>n) {
     7         string a, b;
     8         cin>>a>>b;
     9         string tag;
    10         stack<int> s;
    11         for (int i=0, j=0; i<a.size(); i++) {
    12         /*
    13             如果a[i]  = b[j]说明是进去再出来,如果不相等,说明进去没出来
    14             如果遇到相等的,那么判断栈空,不空则判断后面出站的是否是栈顶元素,如果是继续出栈
    15             123 321
    16             匹配到3,判断2=栈顶2,1=栈顶1,判断完毕,YES 
    17         */ 
    18             if (a[i] != b[j]) {
    19                 tag += "0";
    20                 s.push(a[i]);
    21             } else {
    22                 tag += "01";
    23                 j++;
    24                 while (!s.empty()) {
    25                     if (s.top() == b[j]) {
    26                         tag += "1";
    27                         s.pop();
    28                         j++;
    29                     } else break;
    30                 }
    31             }
    32         }
    33         if (s.empty()) {
    34             cout<<"Yes."<<endl;
    35             for (int i=0; i<tag.size(); i++) {
    36                 if (tag[i] == '1') {
    37                     cout<<"out
    ";
    38                 } else {
    39                     cout<<"in
    ";
    40                 }
    41             }
    42             cout<<"FINISH
    ";
    43         } else {
    44             cout<<"No.
    FINISH
    ";
    45         }
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    人物装备的选取
    状压 + 背包
    村庄之间建立邮局
    woj
    括号匹配算面积(模拟)
    流程控制之if
    周末练习题(第一周)
    day04作业
    流程控制之for
    Python流程控制之while
  • 原文地址:https://www.cnblogs.com/slothrbk/p/7251932.html
Copyright © 2011-2022 走看看