Hdu 1022 Train Problem I 程序参考

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

#pragma warning(disable : 4786)

#include <iostream>

#include <stack>

#include <string>

#include <vector>

using namespace std;



bool run(int now)

{

    int n;

    if (!(cin>>n)) return false;



    string s,t;

    cin>>s>>t;

    stack<int> st;

    vector <string> op;



    int i=0, j=0;

 

    while(i<=n && j<n)

    {

        if (st.empty()==true || st.top()!=t[j])

        {

			st.push(s[i]);

			op.push_back("in");

			i++;

		}

		else

		{

			st.pop();

			op.push_back("out");

			j++;

		}

    }



    if (st.empty()==true)

    {

        cout << "Yes."<<endl;



        for(i=0;i<op.size();i++)

		{

            cout<<op[i]<<endl; 

		}

    }

    else

	{

        cout << "No."<<endl;

	}



    cout << "FINISH"<<endl;



    return true;

}

 

int main()

{    

    int now=1;

    while(run(now++));

    return 0;

}

你可能感兴趣的:(HDU)