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. monsters = (Monster *)malloc(n * sizeof(Monster));
  33.  
  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. }
Success #stdin #stdout 0s 5276KB
stdin
6
stdout
001     lccgaxjqv  : 243  88 253 246 219  69 
002   gbakegcsnym  : 252 164  43 200 100 146 
003         vrvgi  : 195 166 186  65  28 150 
004    wwxzgcfkus  :  41 146 191  76  60   7 
005        mmbejh  : 129 158  74  59 222 102 
006        xnyumh  :  30 205 249  12 144 161