Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active August 29, 2015 14:03
Show Gist options
  • Save cocodrips/e3d523c2b17260ffeddb to your computer and use it in GitHub Desktop.
Save cocodrips/e3d523c2b17260ffeddb to your computer and use it in GitHub Desktop.
ICPC予選2014 D問題
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
using namespace std;
bool encrypt(string encrypted, string candidate){
string used = "";
for (int i = 0; i < encrypted.size(); ++i){
char c = candidate[i];
if (c != 'a' && used.find(c) == string::npos){
used += c;
candidate[i] --;
}
}
return encrypted == candidate;
}
int main(int argc, const char * argv[]){
string str;
while(cin >> str, str != "#"){
std::vector<string> decrypt;
int max = 1 << str.size();
for (int i = 0; i < max; ++i){
string rep = str;
for (int j = 0; j < str.size(); ++j){
if(i & (1 << j) && str[j] != 'z'){
rep[j] = str[j] + 1;
}
}
if(encrypt(str, rep)){
decrypt.push_back(rep);
}
}
sort(decrypt.begin(), decrypt.end());
cout << decrypt.size() << endl;
if (decrypt.size() <= 10){
for (int i = 0; i < decrypt.size(); ++i){
cout << decrypt[i] << endl;
}
} else {
for (int i = 0; i < 5; ++i){
cout << decrypt[i] << endl;
}
for (int i = 0; i < 5; ++i){
cout << decrypt[decrypt.size() - i - 1] << endl;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment