Every permutation of the alphabet up to 29 characters?

后端 未结 13 1305
攒了一身酷
攒了一身酷 2021-02-11 01:23

I\'m attempting to write a program that will generate a text file with every possible permutation of the alphabet from one character up to twenty-nine characters. I\'ve chosen 2

13条回答
  •  感情败类
    2021-02-11 02:08

    void out_perms(std::string word) {
        std::vector indexes(word.size());
        for (size_t i = 0; i < indexes.size(); ++i)
            indexes[i] = i;
        do {
            for (size_t i = 0; i < indexes.size(); ++i)
                std::cout << word[indexes[i]];
            std::cout << std::endl;
        } while (std::next_permutation(indexes.begin(), indexes.end()));
    }
    
    int main(int, char**) {
        out_perms("asdfg");
    }
    

    See http://codepad.org/6lQTPQrG for example output

提交回复
热议问题