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.  
  30. int i, n;
  31. Monster *monsters;
  32. scanf("%d", &n);
  33. monsters = (Monster *)malloc(n * sizeof(Monster));
  34. if(monsters == NULL){
  35. printf("ERROR\n");
  36. return 0;
  37. }
  38.  
  39. for(i = 0; i < n; i++){
  40. monsters[i] = creMonster();
  41. printf("%03d ", i + 1);
  42. priMonster(monsters[i]);
  43. }
  44.  
  45. free(monsters);
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 5280KB
stdin
6
stdout
001   llypwcdoblm  : 149  94 119   8  10  93 
002     nflsjnfnt  : 195  50 207 133  46 211 
003         kanpr  : 178 195 230  71  33  93 
004        nlpbqc  : 184 118 111  30 226  48 
005     ydwthhdju  : 162 110   7 228  84 205 
006          mdnx  :  87 218 169  40 147  31