资源简介
随机分组代码,但是比较局限。输入分组人数和需要分的组数即可,暂时不能支持不平均分组。
代码片段和文件信息
/*
* Created on: 2012-12-2
* Author: LiBoyang CopyRight Reserved!
* Aim:Grouping
*/
#include
#include
void input_1 (int total char name[][100] int counter[]);
void input_2 (int total char name[][100] int counter[]);
void divide_1 (int total int counter[]);
void output (int total int groups char name[][100] int counter[]);
int main() {
int total groups;
printf(“请输入参加分组的总人数和所需要分的组数(如:6 2):“);
while(scanf(“%d %d“ &total &groups) != EOF) {
int counter[groups];
char input[total][100];
if (total % groups == 0) {
input_1 (total input counter);
divide_1 (total counter);
output (total groups input counter);
}
if (total % groups != 0) {
input_2 (total input counter);
}
}
return 0;
}
void divide_1 (int total int counter[]) {
int i = 0 j = 0 temp;
j = rand() % total;
if (i != j) {
temp = counter[i];
counter[i] = counter[j];
counter[j] = temp;
}
}
void input_1 (int total char name[][100] int counter[]) {
int i;
printf(“请输入参加分组的人员名字(如:XXX):\n“);
for (i = 0;i < total;i++) {
counter[i] = i;
scanf(“%s“ name[i]);
}
}
void input_2 (int total char name[][100] int counter[]) {
printf(“少一个人耶,请重新输入!!!\n“);
}
void output (int total int groups char name[][100] int counter[]) {
int i =1 j;
int counts = 0;
printf(“每组人数是%d\n“ total / groups);
printf(“分组情况是:\n“);
printf(“第1组: “);
for (j = 0;j < total;j++) {
counts++;
if (counts % (total / groups) == 0) {
printf(“%s\n“ name[counter[j]]);
if (j != total - 1) {
printf(“第%d组:“ i + 1);
i++;
}
}
else {
printf(“%s “ name[counter[j]]);
}
}
printf(“\n“);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 62629 2012-12-02 00:52 新建文件夹\grouping2.exe
文件 1890 2012-12-02 00:52 新建文件夹\GroupingV2.c
文件 391 2013-04-27 17:16 新建文件夹\Readme.txt
目录 0 2012-12-02 00:53 新建文件夹
----------- --------- ---------- ----- ----
64910 4
评论
共有 条评论