Are there any better methods to do permutation of string?

前端 未结 20 1638
醉话见心
醉话见心 2020-11-27 11:15
void permute(string elems, int mid, int end)
{
    static int count;
    if (mid == end) {
        cout << ++count << \" : \" << elems << end         


        
20条回答
  •  我在风中等你
    2020-11-27 11:52

    In particular, you want std::next_permutation.

    void permute(string elems, int mid, int end)
    {
      int count = 0;
      while(next_permutation(elems.begin()+mid, elems.end()))
        cout << << ++count << " : " << elems << endl;
    }
    

    ... or something like that...

提交回复
热议问题