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. tmp.na[k] = '\0';
  17. for(i = 0; i < 6; i++)
  18. tmp.stts[i] = rand() % 255 + 1;
  19. return tmp;
  20. }
  21.  
  22. void priMonster(Monster m){
  23. printf("%12s : ", m.na);
  24. for(int i = 0; i < 6; i++)
  25. printf("%3d ", m.stts[i]);
  26. printf("\n");
  27. }
  28.  
  29. int main(){
  30. srand((unsigned)time(NULL));
  31. int i, n;
  32. Monster *monsters;
  33. scanf("%d", &n);
  34.  
  35. monsters = (Monster *)malloc(n * sizeof(Monster));
  36.  
  37. if(monsters == NULL){
  38. printf("ERROR\n");
  39. return 0;
  40. }
  41. for(i = 0; i < n; i++){
  42. monsters[i] = creMonster();
  43. printf("%03d ", i + 1);
  44. priMonster(monsters[i]);
  45. }
  46. free(monsters);
  47. return 0;
  48. }
Success #stdin #stdout 0s 5284KB
stdin
4
stdout
001     laxiznhvr  : 167  82 219 167  95  89 
002   wbkrcmjxrun  : 194  22  23 183 125  79 
003      dpmmmdft  : 242  73  38  76  61 137 
004   cenoplfjyau  :  99   9  93 177  25 114