#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,int length) {
static const char alphabet[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(int i=0;i<length;i++) {
name
[i
]=alphabet
[rand()%(sizeof(alphabet
)-1)]; }
name[length]='\0';
}
Monster creMonster() {
Monster monster;
generateRandomName(monster.name,10);
monster.
attack=rand()%50+1; monster.
defense=rand()%50+1; return monster;
}
int main(){
int n;
Monster
*monsters
=(Monster
*)malloc(n
*sizeof(Monster
)); 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); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8dGltZS5oPgoKdHlwZWRlZiBzdHJ1Y3R7CiAgICBjaGFyIG5hbWVbMjBdOwogICAgaW50IGhwOwogICAgaW50IGF0dGFjazsKICAgIGludCBkZWZlbnNlOwp9TW9uc3RlcjsKCnZvaWQgZ2VuZXJhdGVSYW5kb21OYW1lKGNoYXIqbmFtZSxpbnQgbGVuZ3RoKSB7CiAgICBzdGF0aWMgY29uc3QgY2hhciBhbHBoYWJldFtdPSJBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWiI7CiAgICBmb3IoaW50IGk9MDtpPGxlbmd0aDtpKyspIHsKICAgICAgICBuYW1lW2ldPWFscGhhYmV0W3JhbmQoKSUoc2l6ZW9mKGFscGhhYmV0KS0xKV07CiAgICB9CiAgICBuYW1lW2xlbmd0aF09J1wwJzsKfQoKTW9uc3RlciBjcmVNb25zdGVyKCkgewogICAgTW9uc3RlciBtb25zdGVyOwogICAgZ2VuZXJhdGVSYW5kb21OYW1lKG1vbnN0ZXIubmFtZSwxMCk7CiAgICBtb25zdGVyLmhwPXJhbmQoKSUxMDArMTsKICAgIG1vbnN0ZXIuYXR0YWNrPXJhbmQoKSU1MCsxOwogICAgbW9uc3Rlci5kZWZlbnNlPXJhbmQoKSU1MCsxOwogICAgcmV0dXJuIG1vbnN0ZXI7Cn0KCmludCBtYWluKCl7CiAgICBpbnQgbjsKICAgIHNjYW5mKCIlZCIsJm4pOwogICAgTW9uc3Rlciptb25zdGVycz0oTW9uc3RlciopbWFsbG9jKG4qc2l6ZW9mKE1vbnN0ZXIpKTsKICAgIHNyYW5kKHRpbWUoTlVMTCkpOwogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgbW9uc3RlcnNbaV09Y3JlTW9uc3RlcigpOwogICAgfQogICAgcHJpbnRmKCLnlJ/miJDjgZXjgozjgZ/jg6Ljg7Pjgrnjgr/jg7w6XG4iKTsKICAgIGZvciAoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICBwcmludGYoIuODouODs+OCueOCv+ODvCVkOuWQjeWJjT0lcyxIUD0lZCzmlLvmkoPlips9JWQs6Ziy5b6h5YqbPSVkXG4iLGkrMSxtb25zdGVyc1tpXS5uYW1lLG1vbnN0ZXJzW2ldLmhwLG1vbnN0ZXJzW2ldLmF0dGFjayxtb25zdGVyc1tpXS5kZWZlbnNlKTsKICAgIH0KICAgIGZyZWUobW9uc3RlcnMpOwoKICAgIHJldHVybiAwOwp9Cg==
生成されたモンスター:
モンスター1:名前=DRRVLQHHYR,HP=48,攻撃力=46,防御力=13
モンスター2:名前=ZUSTQMYZQQ,HP=98,攻撃力=32,防御力=31
モンスター3:名前=SZKJZNCSKP,HP=64,攻撃力=21,防御力=30