fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5.  
  6. typedef struct {
  7. char na[64];
  8. int stts[6];
  9. } Monster;
  10.  
  11.  
  12. Monster creMonster(){
  13. int i,k;
  14. Monster tmp;
  15. k = rand()%8+4;
  16. int a = 'a' + rand()%26;
  17. for(i=0;i<k;i++) tmp.na[i] = 'a' + rand()%26;
  18. tmp.na[k] = '\0';
  19. for(i=0;i<6;i++) tmp.stts[i] = rand()%255+1;
  20. return tmp;
  21. }
  22.  
  23.  
  24. void priMonster(Monster m){
  25. printf("%12s : ",m.na);
  26. for(int i=0;i<6;i++)
  27. printf("%3d ",m.stts[i]);
  28. printf("\n");
  29. }
  30.  
  31. int main(){
  32. srand((unsigned)time(NULL));
  33. int i, n;
  34. Monster *monsters;
  35. scanf("%d",&n);
  36. monsters = (Monster *)malloc(sizeof(Monster)*n);
  37.  
  38. if(monsters == NULL){
  39. printf("ERROR\n");
  40. return 0;
  41. }
  42. for(i=0;i<n;i++){
  43. monsters[i] = creMonster();
  44. printf("%03d ",i+1);
  45. priMonster(monsters[i]);
  46. }
  47. free(monsters);
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5288KB
stdin
8
stdout
001        lndjdf  :  22 144 136 226 118 230 
002     ythrtrcff  :  37  61  29  84  35  40 
003       mcnxfuc  : 189 156   9 178   2 245 
004          wrvp  :  67 178 212 207 214  17 
005      lxzvlbkj  :  60  28 150 120 183 158 
006   rjancxepwbi  :  79  70 187 247 119 205 
007      phmyprox  : 182  80  55 237  99  95 
008       lmnblqj  :  98 174 169 217  37 118