题目大意:给一个由字母构成的序列,输出按字典序的下一个排列。
用c++ STL的next_permutation可以很容易地解决。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int main() 7 { 8 #ifdef LOCAL 9 freopen("in", "r", stdin); 10 #endif 11 char str[60]; 12 while (gets(str) && str[0] != '#') 13 { 14 if (next_permutation(str, str+strlen(str))) 15 printf("%s\n", str); 16 else printf("No Successor\n"); 17 } 18 return 0; 19 }