Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 986f739

Browse files
Emerson DolinskiEmerson Dolinski
authored andcommitted
Add mapless 8-8 solution.
1 parent bea1e97 commit 986f739

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
void printPerms(string, string = "");
7+
8+
int main()
9+
{
10+
printPerms("abbc");
11+
}
12+
13+
void printPerms(string remainder, string prefix)
14+
{
15+
long length = remainder.length();
16+
17+
if (!length) cout << prefix << endl;
18+
19+
bool dup[128];
20+
21+
memset(dup, false, sizeof(bool) * 128);
22+
23+
for (int i = 0; i < length; ++i)
24+
{
25+
if (dup[remainder.at(i)]) continue;
26+
27+
string str1 = i == 0 ? "" : remainder.substr(0,i);
28+
29+
string str2 = i == length - 1 ? "" : remainder.substr(i+1,length);
30+
31+
printPerms(str1 + str2, prefix + remainder.at(i));
32+
33+
dup[remainder.at(i)] = true;
34+
}
35+
}

0 commit comments

Comments
 (0)