zoukankan      html  css  js  c++  java
  • [算法] 字符串的全排列 [dfs 递归神技]

    字符串的全排列,递归交换
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <vector>
    #include <stack>
    #include <deque>
    #include <queue>
    #include <bitset>
    #include <list>
    #include <map>
    #include <set>
    #include <iterator>
    #include <algorithm>
    #include <functional>
    #include <utility>
    #include <sstream>
    #include <climits>
    #include <cassert>
    #define BUG puts("here!!!");
    
    using namespace std;
    const int N = 1005;
    void swap(char &a, char &b) {
    	char temp = a;
    	a = b;
    	b = temp;
    }
    void f(char *str, char *begin) {
    	if(*begin == '\0') {
    		cout << str << endl;
    		return;
    	}
    	for(char *p = begin; *p != '\0'; p++) {
    		swap(*p, *begin);
    		f(str, begin+1);
    		swap(*p, *begin);
    	}
    }	
    int main() {
    	char s[10] = "abcde";
    	f(s, s);
    	return 0;
    }
    

  • 相关阅读:
    一种想法
    识别link_text
    识别name
    识别id
    文件的读写
    条件和循环
    网站测试-功能测试小结
    拷贝
    #团队博客作业1-小组成员介绍
    软件测试基础-Homework1
  • 原文地址:https://www.cnblogs.com/robbychan/p/3787066.html
Copyright © 2011-2022 走看看