zoukankan      html  css  js  c++  java
  • 编程算法

    版权声明:本文为博主原创文章。未经博主同意不得转载。

    https://blog.csdn.net/u012515223/article/details/35593485

    字符串的排列 代码(C)


    本文地址: http://blog.csdn.net/caroline_wendy


    题目: 输入一个字符串, 打印出该字符串中字符的全部排列.


    方法: 使用递归依次交换位置, 打印输出.


    代码:

    /*
     * main.cpp
     *
     *  Created on: 2014.6.12
     *      Author: Spike
     */
    
    /*eclipse cdt, gcc 4.8.1*/
    
    #include <stdio.h>
    
    void Permutation(char* str, char* begin);
    
    void Permutation(char* str){
        if(str == NULL)
            return;
        Permutation(str, str);
    }
    
    void Permutation(char* str, char* begin) {
        if(*begin == '') {
            printf("%s
    ", str);
            return;
        }
    
    	for (char* c = begin; *c != ''; ++c) {
    		char temp = *c;
    		*c = *begin;
    		*begin = temp;
    
    		Permutation(str, begin + 1);
    
    		temp = *c;
    		*c = *begin;
    		*begin = temp;
    	}
    
    }
    
    void Test(char* pStr)
    {
        if(pStr == NULL)
            printf("Test for NULL begins:
    ");
        else
            printf("Test for %s begins:
    ", pStr);
    
        Permutation(pStr);
    
        printf("
    ");
    }
    
    int main(void)
    {
        char str[] = "abc";
        Test(str);
    
        return 0;
    }
    



    输出:

    Test for abc begins:
    abc
    acb
    bac
    bca
    cba
    cab
    




查看全文
  • 相关阅读:
    【Atcoder】CODE FESTIVAL 2017 qual C D
    【BZOJ】4756: [Usaco2017 Jan]Promotion Counting
    【Luogu】P3933 Chtholly Nota Seniorious
    【BZOJ】1914: [Usaco2010 OPen]Triangle Counting 数三角形
    【算法】计算几何
    【BZOJ】1774: [Usaco2009 Dec]Toll 过路费
    【BZOJ】2200: [Usaco2011 Jan]道路和航线
    【BZOJ】1833 [ZJOI2010]count 数字计数
    【BZOJ】1731: [Usaco2005 dec]Layout 排队布局
    【BZOJ】1577: [Usaco2009 Feb]庙会捷运Fair Shuttle
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10502289.html
  • Copyright © 2011-2022 走看看