You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
int main ( ) {
int a , b , n ; // 最小字母,最大字母,字符串的长度
string s ; // 输入的字符串是什么
cin > > a > > b > > n > > s ;
a - - , b - - ; // 题目中下标从1开始, 为了方便我们修改为从0开始, 所以 a--,b--
for ( int i = 0 ; i < 5 ; i + + ) { // 最多输出5个
int k = n - 1 ;
/*
从后向前枚举, 这是因为如果一个jam数字, 比如bcdef, 可以先从最后下手变成 bcdeg,这样变化最小
如果后面实在变化不了了,才能变化前一位。
判断
(1) 可用字母数量:(s[k]+1-'a')~b
(2) k~n-1 : 当前位置后面的空位(空位的数量n-k)
(3) 如果可用的字母数量可以填充满, 就是找到了一个数字, 否则k这个位置上长大一个的目标就是无法达成的,只能是继续向前找
*/
while ( k > = 0 & & b - ( s [ k ] - ' a ' ) < n - k ) k - - ; // 如果不行,就继续向前
if ( k < 0 ) break ; // 如果每一位都无法变大,说明是最大排列,已经无路可走
// 否则可以变大,变成比现在大的最小的一个,把当前位及后面都调大一位即可
for ( int j = k , c = s [ k ] + 1 ; j < n ; j + + , c + + ) s [ j ] = c ;
cout < < s < < endl ;
}
return 0 ;
}