fork(12) download
  1. #include<stdio.h>
  2. //#include<stdlib.h>
  3. //#include<time.h>
  4. #define TOTAL 88
  5. typedef struct student
  6. {
  7. int st_id;
  8. char st_name[10];
  9. } student;
  10. int main(void)
  11. {
  12. student stu[TOTAL] = {2017213063, "闫思伊", 2017213064, "胡靖", 2017213065, "李宁晏", 2017213066, "于晓艺", 2017213067, "鞠柠谣", 2017213068, "傅宁熙", 2017213069, "王一帆", 2017213070, "王洲洋", 2017213071, "贡辰锋", 2017213072, "费启文", 2017213073, "侯伯", 2017213074, " 刘睿轩", 2017213075, "吴童", 2017213076, "许轩铭", 2017213077, "郭笑通", 2017213078, "马冀", 2017213079, "翁怀远", 2017213080, "刘力铭", 2017213081, "沈鸿瑞", 2017213082, "康凯", 2017213083, "刘鹏", 2017213084, "林韬", 2017213085, "郝则嘉", 2017213086, "张家祺", 2017213087, "黄洛轩", 2017213088, "叶子瑞", 2017213089, "李沐春", 2017213090, "骆俊屹", 2017213091, "杜瑞年", 2017213092, "姜博川", 2017213093, "李欣禹", 2017213094, "杨喆璨", 2017213095, "安婧仪", 2017213096, "吕月", 2017213097, "柴雨彤", 2017213098, "范欣然", 2017213099, "陈昱璇", 2017213100, "高镜云", 2017213101, "崔文谦", 2017213102, "张睿毅", 2017213103, "谢玉涵", 2017213104, "李永昶", 2017213105, "马齐徽", 2017213106, "石培元", 2017213107, "张绮洲", 2017213108, "苗靖", 2017213109, "靳宇钧", 2017213110, "辛沐恒", 2017213111, "宋京印", 2017213113, "张荣泽", 2017213114, "古铭君", 2017213115, "王威", 2017213116, "丁仁杰", 2017213117, "刘时雷", 2017213118, "容柏林", 2017213119, "吴宇阳", 2017213120, "范航", 2017213121, "柏皓然", 2017213122, "闵士尧", 2017213123, "秦子原", 2017213124, "刘喆", 2017213125, "王仪琳", 2017213126, "余涵", 2017213127, "何含玥", 2017213128, "夏雨琴", 2017213129, "罗心怡", 2017213130, "欧阳鸣飞", 2017213131, "孟鹤卿", 2017213132, "施轩", 2017213133, "林麒", 2017213134, "刘澄宇", 2017213135, "李啸东", 2017213136, "彭嘉轩", 2017213137, "王广平", 2017213138, "徐浩轩", 2017213139, "胡振铭", 2017213140, "张博广", 2017213141, "刘至诚", 2017213142, "池晓威", 2017213143, "刘文龙", 2017213144, "宋逸斐", 2017213145, "张小博", 2017213146, "殷实", 2017213147, "林佑光", 2017213148, "明思宇", 2017213149, "祝杰文", 2017213150, "崔展博", 2017213151, "张增煊"};
  13. int selection[TOTAL] = {0}; //selected or not
  14. int number; //how many numbers to select
  15. int s; //selection[s] == 1 means selected
  16. int i; //loop variable
  17.  
  18. //printf("The number of students to generate is \n");
  19. scanf("%d", &number);
  20.  
  21. srand(time(NULL));
  22. for (i = 0; i < number; i++) //loop for generating "number" students
  23. {
  24. do
  25. {
  26. s = rand() % TOTAL;
  27. }
  28. while (selection[s]); //select only not selected
  29. selection[s] = 1; //s is selected
  30. }
  31.  
  32. for (i = 0; i < TOTAL; i++)
  33. if (selection[i])
  34. {
  35. printf("%d %s\n", stu[i].st_id, stu[i].st_name); //print out if selected
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Standard output is empty