1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <stdlib.h>
#include <time.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
enum{Yellow=1,Blue=2,Red=3,Purple=4,Orange=5,Green=6,Maroon=7,Black=8};
int tally[25];
int num, ball, total=0;
srand(time(NULL));
for(int i=0; i=1000; i++)
{
static int arr[]={1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8};
vector<int> vec (arr, arr + sizeof(arr) / sizeof(arr[0]) );
num=rand()%23+1;
ball=vec[num];
total+=ball;
std::swap(vec[num],vec[23]);
vec.pop_back();
num=rand()%22+1;
ball=vec[num];
total+=ball;
std::swap(vec[num],vec[22]);
vec.pop_back();
num=rand()%21+1;
ball=vec[num];
total+=ball;
std::swap(vec[num],vec[21]);
vec.pop_back();
tally[total]++;
}
}
|