从后往前找第一个不是当前位置最大可能值的字母,将这个字母加一,往后依次的值为前一个字母加一。
参考代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cmath> #include<vector> #include<set> #include<sstream> #include<cstring> #include<utility> using namespace std; typedef long long ll; typedef long l; const int N=1<<10+1; int s,t,w,cnt=5;char f[30]; int main(){ scanf("%d%d%d",&s,&t,&w);char c=getchar(); while(c<'a'||c>'z'){ c=getchar(); } f[1]=c; for(int i=2;i<=w;i++)scanf("%c",&f[i]); while(cnt--){ int cnt1=0; for(int i=w,j=t;i>0;i--,j--){ if(f[i]>='a'-1+j){ //cout<<f[i]<<(char)('a'-1+j); cnt1++; continue; } else{ f[i]++; //cout<<f[i]; for(int j=i+1;j<=w;j++)f[j]=f[j-1]+1; break; } } if(cnt1==w)break; for(int i=1;i<=w;i++)printf("%c",f[i]); cout<<endl; } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:650 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:525 |
字符串比较 (C语言代码)答案错误????浏览:596 |
剪刀石头布 (C语言代码)浏览:748 |
1014题解浏览:484 |
C二级辅导-公约公倍 (C语言代码)浏览:481 |
拆分位数 (C语言代码)浏览:514 |
C二级辅导-统计字符 (C语言描述——用函数求解)浏览:1156 |
求教大神。。。。1063,统计字符。浏览:11684 |
WU-蛇行矩阵 (C++代码)浏览:633 |