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. int a = 'a' + rand()%26;
  15. for(i=0;i<k;i++) tmp.na[i] = 'a' + rand()%26;
  16. tmp.na[k] = '\0';
  17. for(i=0;i<6;i++) tmp.stts[i] = rand()%255+1;
  18. return tmp;
  19. }
  20.  
  21. void priMonster(Monster m){
  22. printf("%12s : ",m.na);
  23. for(int i=0;i<6;i++)
  24. printf("%3d ",m.stts[i]);
  25. printf("\n");
  26. }
  27.  
  28. int main(){
  29. srand((unsigned)time(NULL)); //乱数を生成する時のおまじない
  30. int i, n;
  31. Monster *monsters;
  32. scanf("%d",&n);
  33. //ここに1行で monstersにn体のモンスターの領域を確保する
  34. monsters=(Monster*)malloc(sizeof(Monster)*n);
  35.  
  36. //以下はいじらなくてOK
  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. }
  49.  
Success #stdin #stdout 0s 5288KB
stdin
7
stdout
001      tzuqrcim  : 151 106  50 212 243  96 
002      bwvfenmz  :   3  55  97  84 129 200 
003    ajsrlcgpvk  : 150 211 201 200 225 109 
004          smwh  : 229  43 179  70 253  52 
005     pvfkpqovh  : 170  69  90 125  14  34 
006    gfzucigzla  :  14  11  41 186  57 130 
007         kbofj  : 129 198  46 125  83  79