HDU 1022 Train Problem I

http://acm.hdu.edu.cn/showproblem.php?pid=1022

STL中栈的应用练习,数组要开够啊。。。无语

View Code
#include <iostream>
#include <stack>
using namespace std;
int main()
{
    stack <char> s;
    char in[11],out[11];
    int n;
    bool flag[30];
    while(~scanf("%d%s%s",&n,in,out))
    {
        int i,j,cnt;
        i=j=cnt=0;
        while(j<n)
        {
            if(!s.empty() && s.top()==out[j])
            {
                s.pop();
                flag[cnt++]=false;
                j++;    
            }
            else 
            {
                s.push(in[i]);
                flag[cnt++]=true;
                i++;
            }
        }
        if(!s.empty())
            puts("No.");
        else
        {
            puts("Yes.");
            for(i=0;i<cnt;i++)
                if(flag[i])
                    puts("in");
                else
                    puts("out");
        }
        puts("FINISH");
        while(!s.empty())s.pop();
    }
    return 0;
}
原文地址:https://www.cnblogs.com/xiaohongmao/p/2516723.html