C语言随机抽签程序
//BME1班抽签器//
#include<stdio.h> #include<stdlib.h> #include<time.h> #define CLASSMATE_NUM 62 char *name[CLASSMATE_NUM]={ "白天", "邱创辰", "罗杨林", "蔡慕天", "杨爽", "陈章武", "陈卓", "邓贵锋", "黄河翔", "黄俊泓", "蒋佳辰", "蓝荣熙", "林天予", "刘庆彬", "刘岩", "卢冠霖", "魏坚锐", "温钦正", "巫烨力", "伍浩然", "周胤宏", "庄承一", "艾熠恒", "胡文智", "花正荣", "金家臣", "李煦徽", "潘昊宇", "王云彪", "谭晓鹏", "汪远洋", "游若飞", "余辉阳", "张彬彬", "张鹏程", "蔡致宁", "陈丽盈", "陈敏", "陈燕华", "纪嘉蒞", "邓静雯", "陈亿彤", "韩楚欣", "庞昕", "阮柔", "申信", "石颖", "袁雨柔", "张碧昀", "张嘉轩", "张靖宜", "程金玉", "龚晨曦", "张怡馨", "孟楠欣", "欧阳嫣然", "林梦露", "彭佳瑾", "杨思思", "李加林", "姚佳妹", "姚怡然"} ; int main() { int numbers_now,numbers_needed,id,i,count; printf("****************************\n"); printf("BME1班大家庭专属班级活动抽签器\n\n\n\n"); printf("请输入本次抽签需要抽出的人数:\n"); scanf("%d",&numbers_needed); if(numbers_needed>CLASSMATE_NUM) { puts("Not so many classmates!"); exit(0); } printf("本次抽签结果为:\n"); printf("\t人数\t班级排号\t姓名\n"); int list[numbers_needed+1]; list[0]=0; for(numbers_now=1;numbers_now<=numbers_needed;) { srand((int)time(0)); id=rand()%CLASSMATE_NUM; if(id!=0) { for(i=0,count=0;i<numbers_now;i++) { if(id!=list[i]) count++; } if(count==numbers_now) { list[numbers_now]=id; printf("\t%d\t%d\t\t%s\n\n",numbers_now,id,name[id-1]); numbers_now++; } } } printf("抽签结束,恭喜以上同学参加活动!!!\n\n\n\n") ; getchar(); getchar(); getchar(); return 0; }