Last active
August 29, 2015 14:01
-
-
Save evansb/3fa1c7eaa71094f1730d to your computer and use it in GitHub Desktop.
This file contains 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
// Crypt Kicker | |
// Evan Sebastian <[email protected]> | |
#include <cstdio> | |
#include <iostream> | |
#include <stack> | |
#include <string> | |
#include <sstream> | |
#include <set> | |
#include <vector> | |
#include <map> | |
using namespace std; | |
typedef stack<string> crypt; | |
typedef vector<crypt> vcrypt; | |
typedef map<string, string> mapp; | |
string star(int n) { | |
string s = ""; | |
for (int i = 1; i<= n; i++) { | |
s += '*'; | |
} | |
return s; | |
} | |
vector<string> tokenize(string s, char delim) { | |
string word = ""; | |
vector<string> result; | |
for (int i = 0; i < (int)s.size(); i++) { | |
if (s[i] == delim) { | |
result.push_back(word); | |
word = ""; | |
} else { | |
word += s[i]; | |
} | |
} | |
result.push_back(word); | |
return result; | |
} | |
void init(vcrypt& v) { | |
for (int i = 1; i <= 16; i++) { | |
v.push_back(crypt()); | |
} | |
} | |
int main() { | |
int nw; | |
scanf("%i", &nw); | |
vcrypt dict; | |
init(dict); | |
for (int i = 1; i <= nw; i++) { | |
string key; | |
cin >> key; | |
dict.at(key.length()).push(key); | |
} | |
string line; | |
getline(cin, line); | |
while (getline(cin, line)) { | |
vcrypt ddict(dict); | |
vector<string> words = tokenize(line, ' '); | |
vector<string> sentence; | |
mapp smapp; | |
for (int i = 0; i < (int) words.size(); i++) { | |
if (smapp.find(words[i]) != smapp.end()) { | |
sentence.push_back(smapp.find(words[i])->second); | |
} else { | |
int sz = words[i].length(); | |
if (!ddict[sz].empty()) { | |
smapp.insert(make_pair(words[i], ddict[sz].top())); | |
ddict[sz].pop(); | |
sentence.push_back(smapp.find(words[i])->second); | |
} else { | |
goto impossible; | |
} | |
} | |
} | |
goto can; | |
impossible: | |
for(int i = 0; i < (int) words.size() - 1; i++) { | |
cout << star(words[i].length()) << " "; | |
} | |
cout << star(words[(int)words.size() - 1].length()) << endl; | |
continue; | |
can: | |
for (int i = 0; i < (int) sentence.size() - 1; i++) { | |
cout << sentence.at(i) << " "; | |
} | |
cout << sentence.at(sentence.size() - 1) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment