好难啊一个排列组合有关问题

好难啊,一个排列组合问题
问题是这样的:
0-9当中选出5个数,按照一定的奇偶性进行排列组合
比如:全偶, 全奇,偶偶偶偶偶,奇奇奇奇奇,奇偶偶偶偶,奇奇偶偶偶,奇奇奇偶偶......
这样应该一共有2^5=32种情况
对这32种情况下的所有排列组合进行输出,并保存到文件里

我用5层循环写了全奇和全偶两种,其它的不会了,现请教各位,该用什么算法,该怎么写。

附:我自己写的全奇全偶的代码
C/C++ code

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
    char ou[6] = {'0','2','4','6','8','\0'};
    char ji[6] = {'1','3','5','7','9','\0'};

    ofstream out("全偶.txt");
    int cnt = 0;
    for (int a=0; a<5; a++)
    {
        for (int b=0; b<5; b++)
        {
            for (int c=0; c<5; c++)
            {
                for (int d=0; d<5; d++)
                {
                    for (int e=0; e<5; e++)
                    {
                        char temp[6] = {ou[a], ou[b], ou[c], ou[d], ou[e], '\0'};
                        cout << temp << endl;
                        out << temp << ends;
                        cnt++;                        
                    }
                }
            }
        }
    }
    out.close();
    cout << "总数:" << cnt << endl;

    out.open("全奇.txt");
    cnt = 0;
    for (int a=0; a<5; a++)
    {
        for (int b=0; b<5; b++)
        {
            for (int c=0; c<5; c++)
            {
                for (int d=0; d<5; d++)
                {
                    for (int e=0; e<5; e++)
                    {
                        char temp[6] = {ji[a], ji[b], ji[c], ji[d], ji[e], '\0'};
                        cout << temp << endl;
                        out << temp << ends;
                        cnt++;                        
                    }
                }
            }
        }
    }
    out.close();
    cout << "总数:" << cnt << endl;

    return 0;
}



------解决方案--------------------
"对这32种情况下的所有排列组合进行输出,并保存到文件里."
看过你的代码后发现表述有问题:应该是所有排列,而不是排列组合。排列和组合是两个不同的概念。
其实这个问题你换个角度看:
对于任何的排列如:78456,它必然属于一个奇偶排列(奇偶偶奇偶)。这个问题也就是把00000~99999判断奇偶排列放入到对应的文件。这个判断的方法可以用决策树。而把00000~99999遍历只需要一层循环即可。
不知道我理解的是否对?


------解决方案--------------------
从楼主代码看可以重复,大概没什么难度
[code=C/C++][/code]
#include<stdio.h>
#include <fstream>
using namespace std;



int main()
{
int type[5]={0,1,1,0,0};//代表对应位置奇偶,0为偶数1为奇数
ofstream out("test.txt");
int cnt =0;
for (int i =0;i<100000;i++)
{
int j =0;
char szBuffer[32];
sprintf(szBuffer,"%05d",i);
for (j =0;j<5;j++)
{
if (szBuffer[j]%2!=type[j])
break;
}
if (j==5)
{
cnt++;
out <<szBuffer;
out <<"\n";
}
}
out <<cnt;
}