#include <iostream>
#include <ctime>
using namespace std;
void main()
{
const int n = 10;
int x[n];
srand(time(0));
for(int i = 0; i < n; i++)
x[i] = i;
for(int j = 0; j < 10; j++) {
for(int i = 0; i < 5; i++) {
swap(x[i], x[i + rand() % (n - i)]);
cout << x[i] << " ";
}
cout << endl;
}
}
详见:编程珠玑1.6.4
生成小于n且没有重复的k个整数
最新推荐文章于 2018-01-17 22:31:00 发布