闘地主ランダム発アルゴリズムコンソール実装コード
1037 ワード
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
vector<int> v;
void Rand(int n)
{
for(int i = 0; i < n; i++)
{
v.push_back(i + 1);
}
int count = n; //
int next = 1; //
int id = 0;
char* dizhu[] = {" 1: ", " 2: "," : ", " : "};
cout<<dizhu[id];
while(count)
{
srand(time(NULL));
int num = rand() % (count);
if(next++ % 17 == 0)
{
printf("%4d
", v[num]);
printf("%s" ,dizhu[++id]);
}
else
{
printf("%4d", v[num]);
}
vector<int>::iterator it = v.begin() + num;
v.erase(it);
count -= 1;
}
cout<<endl;
}
void main()
{
Rand(54);
}
/*
1: 31 33 41 1 22 52 35 25 26 38 4 36 21 24 44 15 9
2: 17 48 42 2 43 53 37 3 54 32 8 23 46 13 51 7 47
: 27 16 34 5 49 6 18 50 28 12 10 20 40 30 11 14 39
: 19 29 45
*/