zoukankan      html  css  js  c++  java
  • 打印任意字符串排列组合

    #include <iostream>
    #include <string>

    using namespace std;

    void swap(string& s,int i,int j)
    {
    char a = s[i];
    s[i] = s[j];
    s[j] = a;
    }

    void myPrint(string& s, size_t index)
    {
    if (index >= s.size())
    {
    cout << s << endl;
    return;
    }

    for (size_t i = index; i < s.size(); i++)
    {
    swap(s ,index ,i);
    myPrint(s,index+1);
    swap(s, index, i);
    }
    }

    void test(string s)
    {
    myPrint(s, 0);
    cout << endl;
    }

    int main()
    {
    test("");
    test("a");
    test("ab");
    test("abc");
    test("abcd");
    return 0;
    }

  • 相关阅读:
    功能规格说明书
    绝望的作业
    php闭包
    php isset emtpy
    PHP超级全局变量、魔术变量和魔术函数
    死锁的一个例子
    php session cookie
    http状态码301、302
    php浮点数
    学过的设计模式
  • 原文地址:https://www.cnblogs.com/itdef/p/6085926.html
Copyright © 2011-2022 走看看