//4、从1~20之间随机抽取5个数,分别输出抽取出来的5个数和剩余未被抽取的15个数。
//样例输出:
//被抽取的数为:5 9 7 6 3
//未被抽取的数为:1 2 4 8 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
#include<math.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
int a[20],v[20];//标记
int t;
for(int i=0;i<20;i++)
{
a[i]=i;v[i]=0;
}
srand(time(NULL));//rand()使用之前设置随时间变化的种子。
for(int i=0;i<5;)
{
t=rand()%20; //取随机数。0-19
if(v[t]==0)
{
v[t]=1;
cout<<t+1<<" ";
i++;
}
}
cout<<endl;
for(int i=0;i<20;i++)
if(v[i]==0) cout<<a[i]+1<<" ";//进行输出未被选取的数。
return 0;
}
