Skip to content

Instantly share code, notes, and snippets.

@asi1024
Created July 13, 2014 18:12
Show Gist options
  • Save asi1024/5194259511350130b625 to your computer and use it in GitHub Desktop.
Save asi1024/5194259511350130b625 to your computer and use it in GitHub Desktop.
string f(string s) {
for (char c = 'b'; c <= 'z'; c++) {
REP(i,s.size()) {
if (s[i] == c) {
s[i]--;
break;
}
}
}
return s;
}
int main() {
string str;
while (cin >> str, str != "#") {
vector<string> vs;
int len = str.size();
REP(i,1<<len) {
string s = str;
REP(j,len)
if ((i & (1 << j)) && s[j] != 'z') s[j]++;
if (f(s) == str) vs.push_back(s);
}
sort(ALL(vs));
auto it = unique(ALL(vs));
vs.erase(it, vs.end());
cout << vs.size() << endl;
if (vs.size() <= 10) {
REP(i,vs.size()) cout << vs[i] << endl;
}
else {
REP(i,5) cout << vs[i] << endl;
for (int i = vs.size() - 5; i < (int)vs.size(); i++)
cout << vs[i] << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment