fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef struct {
  6. char na[64];
  7. int stts[6];
  8. } Monster;
  9.  
  10. Monster creMonster(){
  11. int i,k;
  12. Monster tmp;
  13. k = rand()%8+4;
  14. int a = 'a' + rand()%26;
  15. for(i=0;i<k;i++) tmp.na[i] = 'a' + rand()%26;
  16. tmp.na[k] = '\0';
  17. for(i=0;i<6;i++) tmp.stts[i] = rand()%255+1;
  18. return tmp;
  19. }
  20.  
  21. void priMonster(Monster m){
  22. printf("%12s : ",m.na);
  23. for(int i=0;i<6;i++){
  24. printf("%3d ",m.stts[i]);
  25. }
  26. printf("\n");
  27. }
  28.  
  29. int main(){
  30. srand((unsigned)time(NULL));
  31. int i, n;
  32. Monster *monsters;
  33. scanf("%d",&n);
  34. monsters=(Monster*)malloc(sizeof(Monster)*n);
  35.  
  36. if(monsters == NULL){
  37. printf("ERROR\n");
  38. return 0;
  39. }
  40. for(i=0;i<n;i++){
  41. monsters[i] = creMonster();
  42. printf("%03d ",i+1);
  43. priMonster(monsters[i]);
  44. }
  45. free(monsters);
  46. return 0;
  47. }
Success #stdin #stdout 0s 5276KB
stdin
7
stdout
001     yrnkvmkyl  :  68  29  79 123 184  25 
002   bozgbeplvva  :  73 136 177 163  47 168 
003    ogfbqpimyq  : 134  99  27 235  43  34 
004     qyjlavdnf  : 151  33 253  40  88 168 
005       xtrkrjg  :  54 130 112 223 163 161 
006          djhd  : 131  34  26 158  56  58 
007      owzzvsqh  : 216  81  93 142 210 204