16,472
社区成员
发帖
与我相关
我的任务
分享
#include <vector>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using std::vector;
using std::cout;
using std::endl;
void Grouping(vector<char> group)
{
for (int i=0;i<6;i++)
{
cout<<"Group "<<i+1<<":";
srand( (unsigned)time( NULL ) );
int pos = abs(rand())%group.size();
cout<<group[pos];
char temp = group[pos]; //将已经分组的成员去除
group[pos] = group[group.size()-1];
group[group.size()-1] = temp;
group.pop_back();
pos = rand()%group.size();
cout<<group[pos]<<endl;
group[pos] = group[group.size()-1];
group[group.size()-1] = temp;
group.pop_back();
}
}
int main()
{
vector<char> g;
g.push_back('a');
g.push_back('b');
g.push_back('c');
g.push_back('d');
g.push_back('e');
g.push_back('f');
g.push_back('g');
g.push_back('h');
g.push_back('i');
g.push_back('j');
g.push_back('k');
g.push_back('l');
Grouping(g);
return 0;
}