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.  
  33. monsters = (Monster *)malloc(n * sizeof(Monster));
  34.  
  35. if (monsters == NULL) {
  36. printf("ERROR\n");
  37. return 0;
  38. }
  39. for (i = 0; i < n; i++) {
  40. monsters[i] = creMonster();
  41. printf("%03d ", i + 1);
  42. priMonster(monsters[i]);
  43. }
  44. free(monsters);
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5284KB
stdin
6
stdout
001       dtooyxa  :  56 247 223  35 212 154 
002    ptabxyjhsd  :   8 255 134 237 249  18 
003   ujvkhumalrc  :   8 243 102 191  71 132 
004    ohkvcppait  :   5  22  17 208 182  35 
005    mrloccsmyz  :  86 166 132 111 126 188 
006          culr  : 212 116 212 216 137 100