

1 #include<iostream> 2 using namespace std; 3 bool Next(char *list,int end,int length); 4 int main() 5 { 6 int s,t,w,i; 7 char a[27]; 8 scanf("%d %d %d",&s,&t,&w); 9 getchar(); 10 for(i=0;i<w;i++)scanf("%c",&a[i]); 11 a[w]='\0'; 12 13 for(i=1;Next(a,t,w) && i<=5;i++) 14 printf("%s\n",a); 15 16 return 0; 17 } 18 19 bool Next(char *list,int end,int length) 20 { 21 bool flag=false; 22 char *p=list+length-1;// *p指向数组list的最后一个元素 23 char max='a'+end-1; // max指向规定的字母内的最后一个 24 for(;;p--,max--) 25 { 26 if(*p<max) 27 { 28 *p=*p+1; 29 for(int j=1;*(p+j);j++) 30 { 31 *(p+j)=*p+j; 32 } 33 flag=true; 34 break; 35 } 36 if(p==list)break; 37 } 38 return flag; 39 }


1 #include <stdio.h> 2 #include <iostream> 3 4 using namespace std; 5 6 const int ASCII_A = 97; 7 8 int s, t, w; 9 int num; 10 char* inputStr; 11 12 void solve() 13 { 14 num = 0; 15 16 for (num = 0; num < w; num++){ 17 char max_char = ASCII_A + t; 18 19 for (int i = w - 1; i > -1; i--){ 20 char temp = inputStr[i] + 1; 21 22 if (temp >= max_char){ 23 max_char = inputStr[i]; 24 continue; 25 } 26 27 if (i < w - 1 && temp > inputStr[i + 1]) 28 break; 29 30 inputStr[i] = temp; 31 32 for (int k = i + 1; k < w; ++k){ 33 inputStr[k] = inputStr[k-1] + 1; 34 } 35 cout << inputStr << endl; 36 break; 37 } 38 39 } 40 } 41 42 int main() 43 { 44 while (cin >> s >> t >> w) 45 { 46 47 inputStr = new char[w+1]; 48 49 cin >> inputStr; 50 51 solve(); 52 53 delete[] inputStr; 54 } 55 56 return 0; 57 }


1 #include<iostream> 2 #include<string.h> 3 #define maxn 107 4 using namespace std; 5 long s,t,w,counter=0; 6 char r[maxn],ans[maxn]; 7 bool first,used[maxn]; 8 9 void dfs(long depth) 10 { 11 if(counter>=5) return; 12 if(depth>=w) 13 { 14 if(first) 15 { 16 first=false; 17 return; 18 } 19 cout<<ans<<endl; 20 counter++; 21 return; 22 } 23 for(long i=(first?r[depth]-'a'+1:ans[depth-1]-'a'+2);i<=t;i++) 24 if(!used[i]) 25 { 26 used[i]=true; 27 ans[depth]=i+'a'-1; 28 dfs(depth+1); 29 used[i]=false; 30 } 31 } 32 33 int main() 34 { 35 cin>>s>>t>>w>>r; 36 // Input 37 memset(ans,0,sizeof(ans)); 38 memset(used,false,sizeof(used)); 39 counter=0; 40 first=true; 41 dfs(0); 42 return 0; 43 }


1 #include <stdio.h> 2 FILE *in,*out; 3 char a,b; 4 int n; 5 6 char str[30]; 7 char s[30]; 8 int o,sum; 9 bool f[30]; 10 bool u; 11 12 void dfs(int k) 13 { 14 char i; 15 if (k > n) 16 { 17 sum ++; 18 if (sum > 1 && sum < 7) 19 { 20 for (i = 1 ;i <= n ;i ++) 21 fprintf(out,"%c",s[i]); 22 fprintf(out,"\n"); 23 } 24 if (sum == 6) 25 u = true; 26 return; 27 } 28 for (i = s[k - 1] + 1 ; i <= b;i ++) 29 { 30 if (o < n) 31 { 32 o ++; 33 i = str[k]; 34 } 35 if (!f[i - 'a']) 36 { 37 s[k] = i; 38 f[i - 'a'] = true; 39 dfs(k + 1); 40 if (u) 41 return ; 42 s[k] = 0; 43 f[i - 'a'] = false; 44 } 45 } 46 } 47 48 int main() 49 { 50 int i; 51 in = fopen("count.in","r"); 52 out = fopen("count.out","w"); 53 fscanf(in,"%d%d%d\n",&a,&b,&n); 54 a += 'a' - 1; 55 b += 'a' - 1; 56 for (i = 1 ;i <= n ;i ++) 57 fscanf(in,"%c",&str[i]); 58 dfs(1); 59 fclose(in); 60 fclose(out); 61 return 0; 62 }