fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. typedef struct monster{
  7. char na[12];
  8. int stts;
  9. }Monster;
  10.  
  11. Monster creMonster(){
  12. Monster m;
  13.  
  14. int len = rand() % 8 + 4;
  15.  
  16. for(int i = 0; i < len; i++){
  17. m.na[i] = 'a' + rand() % 26;
  18. }
  19. m.na[len] = '\0';
  20.  
  21. m.stts = rand() % 255 + 1;
  22.  
  23. return m;
  24. }
  25.  
  26. void priMonster(Monster m){
  27. printf("%-12s : %3d\n", m.na, m.stts);
  28. }
  29.  
  30. int main(){
  31. srand(time(NULL));
  32.  
  33. int n;
  34. scanf("%d", &n);
  35.  
  36. Monster *mons;
  37.  
  38. mons = (Monster *)malloc(sizeof(Monster) * n);
  39.  
  40. for(int i = 0; i < n; i++){
  41. mons[i] = creMonster();
  42. }
  43.  
  44. for(int i = 0; i < n; i++){
  45. priMonster(mons[i]);
  46. }
  47.  
  48. free(mons);
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5320KB
stdin
6
stdout
swywso       :  63
admlxlt      : 164
eqshvzkdj    : 105
extyvtvpj    :  70
jpfuo        : 184
cvtsocnnosy  : 186