Last active
August 29, 2015 14:03
-
-
Save cocodrips/e3d523c2b17260ffeddb to your computer and use it in GitHub Desktop.
ICPC予選2014 D問題
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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