Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Permute
//Title of this code #include <iostream> #include <map> #include <string> using namespace std; void print(string s, map<int, string> m, unsigned* t) { string out = ""; for (int i = 0; i < s.length(); ++i) out += m[i][t[i]]; //cout << t[i]+1 << " "; //cout << endl; cout << out << endl; } void permute(string s, map<int, string> m) { unsigned *t = new(unsigned[s.length()]); for (int i = 0; i < s.length(); ++i) { t[i] = 0; } bool b = true; while (b) { for (int j = 0; j < m[0].length(); ++j) { t[0] = j; print(s, m, t); } if(s.length() > 1) { bool c = false; int j = 1; while (j < s.length() && t[j] < m[j].length()) { if (t[j] < m[j].length() - 1) { ++t[j]; c = false; } else { c = true; t[j] = 0; if (j == s.length() - 1) b = false; ++j; } if (!c) break; } } } delete[] t; } int main() { map<int, string> m; m[0] = "ab"; m[1] = "de"; m[2] = "ghi"; m[3] = "jkl"; m[4] = "mno"; m[5] = "pqr"; m[6] = "stu"; m[7] = "vwx"; m[8] = "yz"; permute("12812", m); }
run
|
edit
|
history
|
help
0
dsadasdsa
anagram
ONP
linkage
Tower Of Hanoi
ForwardListString2
ReplaceGreaterSum in BST
XML parsing with regex
C++ virtual dispose
boost::shared_ptr<base>& arg