代码

 1 #include <iostream>
 2 #include<string>
 3 #include <vector>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 vector<vector<char>> res;
 8 
 9 void getZiji(vector<char> &data)
10 {
11     const int mySize = data.size();
12     int Count = res.size();
13     int i=0,index=0;
14     while (index<mySize)
15     {    
16         Count = res.size();
17         i=0;
18         for (;i<Count;i++)
19         {
20             vector<char> temp;
21             temp = res[i];
22             temp.push_back(data[index]);
23             res.push_back(temp);
24         }
25         index++;
26 
27     }
28 }
29 void getZiji(vector<char> &data,int index)
30 {
31     if(0 == index)
32     {
33         vector<char> temp;
34         temp.push_back(data[index]);
35         res.push_back(temp);
36         return;
37     }
38     getZiji(data,index-1);
39     int Count = res.size();
40     for (int i=0;i<Count;i++)
41     {
42         vector<char> temp;
43         temp = res[i];
44         temp.push_back(data[index]);
45         res.push_back(temp);
46     }
47 }
48 
49 int main()
50 {
51     vector<char> data;
52     data.push_back('a');
53     data.push_back('b');
54     data.push_back('c');
55     vector<char> temp;
56     res.push_back(temp);
57     
58     getZiji(data,data.size()-1);
59     return 0;
60 }