HDU P1022 求教

回复帖子

@黎枔龙 2019-03-15 13:40 回复

传送门

#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<cstdlib>
using namespace std;
int n;
string s1, s2;
int i;
int j;
int destination;
string steck;
int top;
int display[20];
int Move;
bool is_in_the_queue[20];
int main(void)
{
    while(cin >> n)
    {
        cin >> s1;
        cin >> s2;//输入
        memset(is_in_the_queue, true, sizeof(is_in_the_queue));
        steck = "0";
        top = 0;
        i = 0;
        j = 0;//每次重置
        Move = 0;//输出栈的top
        while(i < n && i >= 0)
        {
            destination = s2[j] - '0';//找到目标 
            for(; i < n && i >= 0; i++)
            {
                if(s1[i] - '0' != destination)//如果仍旧不是目标 
                {
                    steck[top] = s1[i];//进栈 
                    display[Move++] = 1;;//记录步数    注:只有这句有问题 
                    is_in_the_queue[s1[i] - '0'] = false;
                //  cout << move[Move - 1]; 
                //  cout << "in" << endl;
                    top++; 
                }
                if(s1[i] - '0' == destination)//如果是目标 
                {   
                    if(is_in_the_queue[destination] == true)
                        display[Move++] = 1, is_in_the_queue[destination] = false;
                    display[Move++] = 0;
                //  cout << "in" << endl;
                //  cout << "out" << endl;
                    top--;
                    i--;
                    break;//退出 
                }
            }
            j++;//累加 
        }
    //  cout << top << endl;
        if(top == -1)//全部进栈 
        {
            cout << "Yes." << endl;
            for(i = 0; i < Move; i++)
            {   if(display[i] == 1)
                    cout << "in" << endl;
                else
                    cout << "out" << endl;
        }
        }
        else 
            cout << "No." << endl;
        cout << "FINISH" << endl;
    }
}

WA 求教