嗯,名单是我们班同学的名单,我注释掉了,你们自己添加,有C++基础应该不难的。
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
const int N = 20000;
string b[]={"\0",
// 分组名单,如"张三","lisi",等等
};
struct xinxi_1802
{
int date;
int index;
};
int cmp(const void *a,const void *b)
{
return ((struct xinxi_1802*)a)->date - ((struct xinxi_1802*)b)->date;
}
void choice_a_to_n(int *a,int first,int n)
{
int i;
struct xinxi_1802 number[N];
srand((int)time(0));
for(i=0;i<n;i++){
number[i].date=rand();
number[i].index=i+1;
}
qsort(number+first-1,n-first+1,sizeof(number[0]),cmp);
for(i=0;i<n;i++){
a[i]=number[i].index;
// cout<<a[i]<<'e'<<endl;
}
}
int main()
{
int n;
int first;
cout<<"start: ";
cin>>first;
cout<<"end: ";
cin>>n;
int split;
cout<<"每组的成员数:";
cin>>split;
int a[N];
choice_a_to_n(a,first,n);
for(int i=0;i<n-first+1;i++){
if(i%split==0){
cout<<endl;
cout<<"第"<<(i/split+1)<<"组:";
cout<<endl;
}
cout<<b[a[i+first-1]]<<endl;
}
return 0;
}