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. for(i=0;i<k;i++) tmp.na[i] = 'a' + rand()%26;
  15. tmp.na[k] = '\0';
  16. for(i=0;i<6;i++) tmp.stts[i] = rand()%255+1;
  17. return tmp;
  18. }
  19.  
  20. void priMonster(Monster m){
  21. printf("%12s : ",m.na);
  22. for(int i=0;i<6;i++)
  23. printf("%3d ",m.stts[i]);
  24. printf("\n");
  25. }
  26.  
  27. int main(){
  28. srand((unsigned)time(NULL));
  29. int i, n;
  30. Monster *monsters;
  31. scanf("%d",&n);
  32. monsters = (Monster*)malloc(sizeof(Monster) * n);
  33.  
  34. if(monsters == NULL){
  35. printf("ERROR\n");
  36. return 0;
  37. }
  38. for(i=0;i<n;i++){
  39. monsters[i] = creMonster();
  40. printf("%03d ",i+1);
  41. priMonster(monsters[i]);
  42. }
  43. free(monsters);
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5312KB
stdin
6
stdout
001      seidydwt  : 111 123  34 214 111 248 
002     gycfcaflg  :  52  24  80  61 232 135 
003    sxmvvstozr  : 193 192 178 185 173 169 
004        fvsibf  :  12 237  91  91 170 194 
005         ddrra  : 156 146 102 189 251  40 
006   hximoaujvcm  : 197  10 200 160 228 114