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 5280KB
stdin
5
stdout
001         wqthx  :  91  25  12  69  21 224 
002        iuvffn  : 171 208 202 131 161 124 
003        qlmlhc  :  66  89 114  28 113 126 
004        igwsds  : 108  66 160 150 145 106 
005   pmfhzttgyay  :  77  61 106  74 157 110