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. printf("\n");
  26. }
  27.  
  28. int main() {
  29. srand((unsigned)time(NULL));
  30. int i, n;
  31. Monster *monsters;
  32.  
  33. scanf("%d", &n);
  34.  
  35. monsters = (Monster *)malloc(n * sizeof(Monster));
  36. if (monsters == NULL) {
  37. printf("ERROR\n");
  38. return 0;
  39. }
  40.  
  41. for (i = 0; i < n; i++) {
  42. monsters[i] = creMonster();
  43. printf("%03d ", i + 1);
  44. priMonster(monsters[i]);
  45. }
  46.  
  47. free(monsters);
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 5288KB
stdin
8
stdout
001         lfvgw  :  90   8  84 223 206  51 
002       zmnjrjz  :   1 169 179 129 124 171 
003   hghsncbkbmn  :   3  13 146 200 192  25 
004        ovynno  : 101  80  45  16 141  57 
005     roytpkudx  : 185 109  17 129 173 168 
006         uushj  :  70 212 251 114 227   8 
007   ckicfxocbnh  :  97 170 117  14  82   1 
008     bzzkhmytn  :   9 142  58 242   2 169