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. }
  17. tmp.na[k] = '\0';
  18. for (i = 0; i < 6; i++) {
  19. tmp.stts[i] = rand() % 255 + 1;
  20. }
  21. return tmp;
  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. }
  29. printf("\n");
  30. }
  31.  
  32. int main() {
  33. srand((unsigned)time(NULL));
  34. int i, n;
  35. Monster *monsters;
  36.  
  37. scanf("%d", &n);
  38.  
  39. monsters = (Monster *)malloc(n * sizeof(Monster));
  40.  
  41. if (monsters == NULL) {
  42. printf("ERROR\n");
  43. return 0;
  44. }
  45. for (i = 0; i < n; i++) {
  46. monsters[i] = creMonster();
  47. printf("%03d ", i + 1);
  48. priMonster(monsters[i]);
  49. }
  50. free(monsters);
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 5284KB
stdin
6
stdout
001   waajuelzdtb  : 179  82 149 193 117  56 
002       zrtdwxj  :  63  50  33  10 116 129 
003   ysisztteoxh  :  95 150 196  83  78 191 
004       pvanvmj  :  82  10 138  69 138 126 
005          pxno  : 214 209  97 226 210 228 
006     jtojtlyrm  : 120  90 168 120  43 177