闲着也是没事,100分拿来!// Prog6.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>/*
新年好。
有两个字符串abcd和ABCD,要求产生出[a,A][b,B][c,C][d,D]
所有组合成的字符串,即分别为:abcd,abcD,abCd,abCD,aBcd,
aBcD,aBCD,aBCd。我只想到了要用一个两维数组,但接
下来,怎么进行组合,一筹莫展,唉,以前,线性代数没有学
好,才看到了自身的差距。高级程序员很多都是数学系出来的
结论看来还是正确的。高手请接招。(只用写出算法描述,不
用VB写过程也行)(另外刚看了电影无间道,不错不错,建议
大家写完这个算法后看看这部电影。)
*//*
本程序采用递归实现题目要求[C语言]
作者:马洪喜 
CSDN账号:mahongxi(烤鸡翅膀)(色摸)
*/#define ROWS 4 //多维数组行数
#define COLS 2 //多维数组列数
#define DISPLAY_ROWS_OF_ONE_PAGE 40 //显示器每页显示行数/*下面为字符数组,注意存储方式
本数组支持横向及纵向扩展,但要
注意更改 ROWS 、COLS值
*/
char g_ch[ROWS][COLS] = {
'a','A',
'b','B',
'c','C',
'd','D'
};
char chResult[255]; //用于存放结果字符串
int g_index = 0; //在chResult中做游标
int g_number = 0; //统计个数//诊断函数
void assert(char *msg)
{
cout<<endl<<msg<<endl; exit(1);
}/*
函数名:fun
参数:
ch -- 字符数组
R  -- 字符数组行数
C  -- 字符数组列数
说明:本程序主要函数,递归结构实现
*/
void fun(char *ch,int R,int C)
{
if(R == 0)
{
chResult[++g_index] = '\0';
cout <<chResult 
 <<"      "
 <<++g_number<< endl; if(g_number %DISPLAY_ROWS_OF_ONE_PAGE == 0)
{
getch();
}//end of if(g_number... return;
}//end of if(R == 0)

for(int j = 0; j < C; j++)
{
g_index = ROWS - R;
chResult[g_index] = *(ch + j); 
fun(&g_ch[ROWS - R + 1][0],R - 1,C);
}//end of for
}//end of function
void main(void)
{
if(ROWS < 1 || COLS < 1)
{
assert("Error!");
} fun(&g_ch[0][0],ROWS,COLS); //invoke fun
}