B - Bus of Characters (STACK-模拟)

#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
struct node
{
    int order,num;
} a[maxn];
bool cmp(node a,node b)
{
    return a.num>b.num;
}
int main()
{
    string str;
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].num;
        a[i].order=i+1;
    }
    stack<node>one;
    stack<node>two;
    sort(a,a+n,cmp);
    for(int i=0; i<n; i++)
        one.push(a[i]);
    cin>>str;
    for(int i=0; str[i]; i++)
    {
        if(str[i]=='0')
        {
            if(i==0)
                cout<<one.top().order;
            else
                cout<<" "<<one.top().order;
            two.push(one.top());
            one.pop();
        }
        else
        {
            if(i==0)
                cout<<two.top().order;
            else
                cout<<" "<<two.top().order;
            two.pop();
        }
    }
    cout<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/BePosit/article/details/81538316