Skip to content

Instantly share code, notes, and snippets.

@idimiter
Created June 7, 2017 05:28
Show Gist options
  • Save idimiter/8d4a8bc6cbdd91bba745e7afc346ede3 to your computer and use it in GitHub Desktop.
Save idimiter/8d4a8bc6cbdd91bba745e7afc346ede3 to your computer and use it in GitHub Desktop.
Simple anagram solver
#include <iostream>
#include <algorithm>
#include <vector>
int main(int ac, char* av[]) {
std::vector<std::string> permlist = {"test", "This", "is"};
if (ac > 1) {
permlist.clear();
for (int i = 1; i < ac; i++)
permlist.push_back(av[i]);
}
std::sort (permlist.begin() , permlist.end());
do {
for (const auto& p : permlist)
std::cout << p << ' ';
std::cout << std::endl;
} while ( std::next_permutation(permlist.begin(), permlist.end()) );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment