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++)
  15. tmp.na[i] = 'a' + rand() % 26;
  16. tmp.na[k] = '\0';
  17. for (i = 0; i < 6; i++)
  18. tmp.stts[i] = rand() % 255 + 1;
  19. return tmp;
  20. }
  21.  
  22. void priMonster(Monster m) {
  23. printf("%12s : ", m.na);
  24. for (int i = 0; i < 6; i++)
  25. printf("%3d ", m.stts[i]);
  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.  
  35. monsters = (Monster *)malloc(n * sizeof(Monster));
  36.  
  37. if (monsters == NULL) {
  38. printf("ERROR\n");
  39. return 0;
  40. }
  41. for (i = 0; i < n; i++) {
  42. monsters[i] = creMonster();
  43. printf("%03d ", i + 1);
  44. priMonster(monsters[i]);
  45. }
  46. free(monsters);
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 5276KB
stdin
9
stdout
001        diymsf  :  24   2 148  22  21 193 
002       ncaapxq  :   7 234 222  54  32 166 
003   ehzsmhtybay  : 148 206 203  40 143 101 
004   jrrbqjusmjp  : 130  90 246 183  76  16 
005   gjihkierkgy  :  12 140 221 207 226 211 
006       cedrptf  : 217  64 115 164 206 121 
007      pvabeguo  : 162  35 172 173 255 124 
008         ovkuz  :  41 162 213 101 250  21 
009    moxgftigzp  : 195 137 108 229  53  25