赛车平台出租 字符串的组合

赛车平台出租【企 娥:217 1793 408】
#include<iostream>

#include<vector>

#include<cstring>

#include<cstdlib>

using namespace std;

void CombinationCore(char * str, int len, vector<char> &rs)

{

if(len == 0)//相当于此时的组合串的长度满足最开始的要求了,即m==0

{

    vector<char>::iterator it;

    for(it = rs.begin(); it < rs.end(); it++)

        cout<<(*it);

    cout<<endl;

    return;

}

if(*str == '\0')//即n == 0

    return;

rs.push_back(*str);

//把当前字符当做组合的一部分

CombinationCore(str + 1,len - 1,rs);

rs.pop_back();//删除当前字符,恢复之前的状态

//不把当前字符作为组合的一部分

CombinationCore(str + 1, len,rs);

}

void getCombination(char* str)

{

if(str == NULL)

    return;

int length = strlen(str);

vector<char> rs;

for(int i = 1; i <= length; i++)

    CombinationCore(str,i,rs);

}

int main()

{

char s[] = "abcd";

getCombination(s);

}

猜你喜欢

转载自blog.51cto.com/13944444/2165841