题意:给一个字符串,你可以对任意一个位置的字符进行操作,把这个字符变成ASCII码+1的字符,任意一个位置的字符可以多次操作,但操作只能从小往大变。然后判断是否可以出现一个子序列为a-z。
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
int a[30],fg=97;
cin>>s;
if(s.size()<26)
cout<<"-1"<<endl;
else
{
memset(a,0,sizeof(a));
int pos=0;
for(int i=0; i<s.size(); i++)
{
if(pos==26)
break;
if(s[i]<=fg)
{
a[pos++]=i;
fg++;
}
}
if(a[25])
{
pos=0;
for(int i=0; i<s.size(); i++)
{
if(i==a[pos])
{
printf("%c",pos+97);
pos++;
}
else
cout<<s[i];
}
cout<<endl;
}
else
cout<<"-1"<<endl;
}
return 0;
}