【高分悬赏~】C语言的一个关于随机抽取的问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 15:35:58
有六个字母a-f,每一次随机抽取其中三个字母(例如:abc,cdf,def..单次抽取中三个字母不能重复),然后重复以上操作,当第N次后,刚好取遍所有的a-f六个字母。输出N值。

然后按照上面方法,重复运行,输出多个N值(因为是随机抽所以N是变量)。

结束。

希望高手能给出全码~~~~~

除去代码中间的注释可以看到选字母的过程.

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"

#define TIME 10 //运行TIME次

int main(){
time_t t;
time(&t);
srand(t);
char staout[256];
char stain[256];
int ti;
for(ti=0;ti<TIME;++ti){
memset(staout,0,256);
char c;
int i;
int count=0;
int numout=0;
while(numout<6){
int numin=0;
memset(stain,0,256);
while(numin<3){
do{
c=rand()%6+'a';
}
while(stain[c]==1);
stain[c]=1;
// printf("%c ",c); //去掉这里和下面的注释可以看到过程
++numin;
}
// printf("\n");
for(i='a';i<='f';++i){
if(stain[i]==1){
if(staout[i]==0){
++numout;
}
staout[i]=1;
}
}
++count