题目链接:http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=10931#problem/F
源代码:
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define max 500010
int a[max],b[max];
int test;
char gw[max+5];
int main()
{
int n;
while(cin>>test)
{
for(int i=0;i<test;i++)
{
cin>>n;
for(int j=1;j<=n;j++)
{
cin>>a[j];
b[a[j]]=j;
}
b[n+1]=0;
int per,next;
per=a[1];
gw[a[1]]='a';
int t;
for(t=2;t<=n;t++)
{
next=a[t];
if(next==n) gw[next]=gw[per]+1;
else if(b[next+1] < b[per+1]) gw[next]=gw[per]+1;// b[n+1]=0;在这用到的
else gw[next]=gw[per];
if(gw[next]>'z') break;//超过了范围的字母
per=next;
}
if(t<=n)
{
cout<<"-1"<<endl;
continue;
}
for(int k=1;k<=n;k++)
cout<<gw[k];
cout<<endl;
}
}
}