找到字符串里面的所有字符,循环右移一位。
#include<bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> PII;
const int N=3e5+10;
const int M=1e3+10;
int mod=1e9+7;
int a[N];
void solve(){
string s;cin>>s;
vector<int> v(30);
int cnt=0;
for(auto it:s){
if(v[it-'a']==0){
v[it-'a']=1;
cnt++;
}
}
if(cnt<2){
cout<<"-1\n";
return ;
}
char las='#';
map<char,char>mp;
int pos;
for(int i=0;i<26;i++){
if(v[i]){
if(las=='#') pos=i;
mp[(char)(i+'a')]=las;
las=(char)(i+'a');
}
}
mp[(char)(pos+'a')]=las;
for(auto it:s) cout<<mp[it];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int _;
_=1;
//cin>>_;
while(_--){
solve();
}
}

京公网安备 11010502036488号