fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5.  
  6. typedef struct {
  7. char na[64];
  8. int stts[6];
  9. } Monster;
  10.  
  11.  
  12. Monster creMonster(){
  13. int i,k;
  14. Monster tmp;
  15. k = rand()%8+4;
  16. int a = 'a' + rand()%26;
  17. for(i=0;i<k;i++) tmp.na[i] = 'a' + rand()%26;
  18. tmp.na[k] = '\0';
  19. for(i=0;i<6;i++) tmp.stts[i] = rand()%255+1;
  20. return tmp;
  21. }
  22.  
  23.  
  24. void priMonster(Monster m){
  25. printf("%12s : ",m.na);
  26. for(int i=0;i<6;i++)
  27. printf("%3d ",m.stts[i]);
  28. printf("\n");
  29. }
  30.  
  31. int main(){
  32. srand((unsigned)time(NULL)); //乱数を生成する時のおまじない
  33. int i, n;
  34. Monster *monsters;
  35. scanf("%d",&n);
  36. monsters = (Monster *)malloc(sizeof(Monster)*n);
  37. //以下はいじらなくてOK
  38. if(monsters == NULL){
  39. printf("ERROR\n");
  40. return 0;
  41. }
  42. for(i=0;i<n;i++){
  43. monsters[i] = creMonster();
  44. printf("%03d ",i+1);
  45. priMonster(monsters[i]);
  46. }
  47. free(monsters);
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5260KB
stdin
5
stdout
001       jylebkh  : 226 118 103  99 175 212 
002          msda  :  18  64 106  24  58  57 
003   wrpacnngqxq  : 102 106  55 200 152  12 
004        sonune  : 145  35 244 201  59 164 
005    iqaxdhpazk  : 245 126 201  14   9 186