hdu 1022

来源:互联网 发布:sql delete加标记 编辑:程序博客网 时间:2024/05/16 01:15

没什么好说,还是练STL

#include <iostream>#include <stdio.h>#include <vector>#include <stack>#include <algorithm>using namespace std;int main(){   // freopen("in.txt","r",stdin);    string train;    string trainOrder;    vector<string> answer;    int trainIndex;    int trainOrderIndex;    int numOfTrain;    stack<char> trainStack;    while( cin >> numOfTrain >> train >> trainOrder)    {        trainIndex = 0;        trainOrderIndex = 0;        while(!trainStack.empty())        trainStack.pop();        answer.clear();        while(trainOrderIndex < trainOrder.length())        {            if(trainStack.empty() || trainOrder[trainOrderIndex] != trainStack.top())            {                answer.push_back("in");                trainStack.push(train[trainIndex]);                trainIndex++;                if(trainIndex > train.length())                break;            }            else            {                answer.push_back("out");                trainStack.pop();                trainOrderIndex++;            }        }        if( trainOrderIndex != trainOrder.length())            {                printf("No.\n");                printf("FINISH\n");            }            else            {                printf("Yes.\n");                for(int i=0 ;i<answer.size() ;i++)                cout << answer[i] << endl;                printf("FINISH\n");            }    }    return 0;}