#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// モンスター構造体の定義
typedef struct {
char name[20];
int hp;
int attack;
int defense;
} Monster;
// ランダムな名前を生成する関数
void generateRandomName(char *name) {
const char *names[] = {"Goblin", "Dragon", "Troll", "Ogre", "Elf"};
int index
= rand() % 5; // 0から4のランダムなインデックス }
// モンスターを生成する関数
Monster *creMonster() {
Monster
*newMonster
= (Monster
*)malloc(sizeof(Monster
)); if (newMonster == NULL) {
}
generateRandomName(newMonster->name);
newMonster
->hp
= rand() % 100 + 50; // HPは50~149の範囲 newMonster
->attack
= rand() % 50 + 10; // 攻撃力は10~59の範囲 newMonster
->defense
= rand() % 50 + 10; // 防御力は10~59の範囲 return newMonster;
}
int main() {
int n;
// モンスターの数を入力
printf("生成するモンスターの数を入力してください: ");
// 動的にモンスター配列を確保
Monster
**monsters
= (Monster
**)malloc(n
* sizeof(Monster
*)); if (monsters == NULL) {
return 1;
}
// モンスターを生成して配列に格納
for (int i = 0; i < n; i++) {
monsters[i] = creMonster();
}
// モンスターの情報を出力
for (int i = 0; i < n; i++) {
printf("モンスター%d: %s (HP: %d, 攻撃力: %d, 防御力: %d)\n", i + 1, monsters[i]->name, monsters[i]->hp, monsters[i]->attack, monsters[i]->defense);
}
// メモリの解放
for (int i = 0; i < n; i++) {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8dGltZS5oPgoKLy8g44Oi44Oz44K544K/44O85qeL6YCg5L2T44Gu5a6a576pCnR5cGVkZWYgc3RydWN0IHsKICAgIGNoYXIgbmFtZVsyMF07CiAgICBpbnQgaHA7CiAgICBpbnQgYXR0YWNrOwogICAgaW50IGRlZmVuc2U7Cn0gTW9uc3RlcjsKCi8vIOODqeODs+ODgOODoOOBquWQjeWJjeOCkueUn+aIkOOBmeOCi+mWouaVsAp2b2lkIGdlbmVyYXRlUmFuZ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