精华(代码)只有 这几句:
```
// do {
Continue220:
++intShootN; //(多)射一次;
inRand = rand() % inCoun; //有多少张信用卡,就射击出多少 数字(范围
Aa[inRand] += 1; // 相应的(编号的)信用卡,消费次数加+1;
if (intShootN < inCoun) goto Continue220; //射击次数 <小于 信用卡 张数, 那必须 继续(重复)射击;
//检查是否所有信用卡都消费过了:
for (int j = 0; j < inCoun; ++j) {//for220j
if (0 == Aa[j]) goto Continue220; //有一张卡没消费过,那么就 (重复循环)再次射击(消费)去
}//for220j
//到这说明 编号 1~编号 inCoun的信用卡 都消费过了
ArrCount[ii] = intShootN; //至此,得到了,消费过所有 信用卡后 的 射击次数;;把(本局)射击(消费的次数)记录到数组里,便于后面统计
goto MeiZhang_Xinyongka_dou_xiaoFei_guoLe440; //每个、每张信用卡 都 消费过了!
```
```
// 21sixCreaditConA210701.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//
#include <iostream>
#define Min2 2
#define MaxCardNum10 20
//2
#define M1000 10000 //一共有多少组消费者, 多少局信用卡消费 (组织
double ArrStatisticFrequency[MaxCardNum10];
int ArrSF_min[MaxCardNum10];
unsigned long int ArrSF_Max[MaxCardNum10];
unsigned int intCountNum = 0;
unsigned int Aa[M1000];
unsigned int ArrCount[M1000];
int main()
{
{//110
std::cout << std::endl;
//
for (int inCoun = Min2; inCoun <= MaxCardNum10; ++inCoun) {//for220inCoun //inCoun是这一次(循环)信用卡的张数……从2张卡到 MaxCardNum10
//
//
ArrSF_min[inCoun] = M1000;
ArrSF_Max[inCoun] = 0;
//
{
int intShootN = 0; //最重要的统计变量:射光信用卡的射击次数; 这个intShootN记录射击的 第intShootN 次(次数;
//射击测试Start:
for (int ii = 0; ii < M1000; ++ii) {//for110ii //每组信用卡都 测试 M1000 次 Start:
//初始化信用卡:
for (int i = 0; i <= inCoun; ++i) { Aa[i] = 0; } //i < MaxCardNum10; ++i) { Aa[i] = 0; } //或 for(int i=0;i<=inCoun 也就 可以了!
//初始化信用卡End;
//用 do 反复 射击或消费:
int inRand = 0;
intShootN = 0;
// do {
Continue220:
++intShootN; //(多)射一次;
inRand = rand() % inCoun; //有多少张信用卡,就射击出多少 数字(范围
Aa[inRand] += 1; // 相应的(编号的)信用卡,消费次数加+1;
if (intShootN < inCoun) goto Continue220; //射击次数 <小于 信用卡 张数, 那必须 继续(重复)射击;
//检查是否所有信用卡都消费过了:
for (int j = 0; j < inCoun; ++j) {//for220j
if (0 == Aa[j]) goto Continue220; //有一张卡没消费过,那么就 (重复循环)再次射击(消费)去
}//for220j
//到这说明 编号 1~编号 inCoun的信用卡 都消费过了
ArrCount[ii] = intShootN; //至此,得到了,消费过所有 信用卡后 的 射击次数;;把(本局)射击(消费的次数)记录到数组里,便于后面统计
goto MeiZhang_Xinyongka_dou_xiaoFei_guoLe440; //每个、每张信用卡 都 消费过了!
// } while (true);//
MeiZhang_Xinyongka_dou_xiaoFei_guoLe440: //
;
//
}//for110ii //每组信用卡都 测试 M1000 次_End
//射击测试End;
//
//统计平均射击次数(在 inCoun 张信用卡的 实验中:
unsigned long int uliTotal = 0;
double doubTotal = 0.0;
for (int ii = 0; ii < M1000; ++ii) {//for2200ii
//
uliTotal += (unsigned long int)ArrCount[ii];
doubTotal += (double)ArrCount[ii];
if (ArrCount[ii] < ArrSF_min[inCoun]) { ArrSF_min[inCoun] = ArrCount[ii]; }
if (ArrCount[ii] > ArrSF_Max[inCoun]) { ArrSF_Max[inCoun] = ArrCount[ii]; }
// std::cout << "[" << ii << "i:" << ArrCount[ii] << "]; ";
//
}//for2200ii
//统计完 doubTotal , 求平均值
double averag_Total = 0.0;
averag_Total = doubTotal / M1000;
averag_Total = (double)uliTotal / (double)M1000;
//
ArrStatisticFrequency[inCoun] = averag_Total;
double averag02 = 0.0;
for (int i = 1; i <= inCoun;++i) {
averag02 += (1.0/(double)i) *inCoun;
}
std::cout << "[CardNums:" << inCoun << ",AverQiWang:" << averag_Total << "),";
std::cout << "minNum:" << ArrSF_min[inCoun];
std::cout << ", Maxnum:" << ArrSF_Max[inCoun];
std::cout<<"; Averag:"<<averag02 << std::endl;
//
}
//
//
}//for220inCoun
}//110
std::cout << "Hello World!_End!!\n";
}//
```