還有這一題@@~有大大可幫我解嗎??
/* (一) 模擬擲骰子 II */
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int p2a(int dist[6]) { // 產生擬骰子點數
int sum=0;
int i;
for(i=0; i<6; i++)
sum+=dist[i];
int chk=0;
int r=rand()%sum;
for(i=0; i<6; i++) {
chk+=dist[i];
if (r<chk)
return i+1;
}
return 0;
}
void sim(int dist[6], int cnt[6], int runs) { // 模擬骰子點數
//在這加入你的程式碼
}
void printC(int cnt[6]) { // 統計骰子點數總和
//在這加入你的程式碼
}
void printP(int cnt[6]) { // 統計骰子點數機率
//在這加入你的程式碼
}
int main() { //主程式
int d[] = {1,1,1,1,1,5};
int cnt[] = {0,0,0,0,0,0};
sim(d,cnt,20000);
printC(cnt);
printP(cnt);
system("pause");
return 0;
}
|