fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <complex>
  4. #include <vector>
  5. #include <utility>
  6. #include <algorithm>
  7. #include <cassert>
  8. #include <queue>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. using namespace std;
  13.  
  14. #define rep(i, n) for (int i = 0; i < (int)(n); i++)
  15.  
  16. vector<string> ans;
  17.  
  18. void search(string s, char c) {
  19. if (c == 'a') {
  20. ans.push_back(s);
  21. } else {
  22. rep (i, s.length()) {
  23. if (s[i] == c) return;
  24.  
  25. if (s[i] == c - 1) {
  26. string t(s);
  27. t[i] = c;
  28. search(t, c - 1);
  29. }
  30. }
  31. search(s, c - 1);
  32. }
  33. }
  34.  
  35. int main() {
  36. for (;;) {
  37. string S;
  38. cin >> S;
  39. if (S == "#") return 0;
  40.  
  41. ans.clear();
  42. search(S, 'z');
  43.  
  44. sort(ans.begin(), ans.end());
  45. ans.erase(unique(ans.begin(), ans.end()), ans.end());
  46. printf("%d\n", (int)ans.size());
  47. if (ans.size() < 10) {
  48. for (string s : ans) cout << s << endl;
  49. } else {
  50. rep (i, 5) cout << ans[i] << endl;
  51. rep (i, 5) cout << ans[ans.size() - 5 + i] << endl;
  52. }
  53. }
  54. }
  55.  
Success #stdin #stdout 0.02s 4120KB
stdin
enw
abc
abcdefghijklmnopqrst
z
#
stdout
1
fox
5
acc
acd
bbd
bcc
bcd
17711
acceeggiikkmmooqqssu
acceeggiikkmmooqqstt
acceeggiikkmmooqqstu
acceeggiikkmmooqrrtt
acceeggiikkmmooqrrtu
bcdefghijklmnopqrrtt
bcdefghijklmnopqrrtu
bcdefghijklmnopqrssu
bcdefghijklmnopqrstt
bcdefghijklmnopqrstu
0