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. Monster creMonster(){
  10. int i,k;
  11. Monster tmp;
  12. k = rand()%8+4;
  13. int a = 'a' + rand()%26;
  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. void priMonster(Monster m){
  20. printf("%12s : ",m.na);
  21. for(int i=0;i<6;i++)
  22. printf("%3d ",m.stts[i]);
  23. printf("\n");
  24. }
  25.  
  26. int main(){
  27. srand((unsigned)time(NULL)); //乱数を生成する時のおまじない
  28. int i, n;
  29. Monster *monsters;
  30. scanf("%d",&n);
  31.  
  32. monsters=malloc(n*sizeof(Monster));
  33.  
  34. //以下はいじらなくてOK
  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 5320KB
stdin
6
stdout
001          wenu  :  70  68 176 145 132 211 
002    huvjgsblpq  : 239 214 236 152  35 228 
003          wawl  :   1  89  69  49 105  72 
004     swoqhwikh  : 171 101 111 130  81 135 
005         ahcce  : 217 168 235  30 216 212 
006    rgvhyedgom  : 133 121  30 134  74 164