码蹄集网站地址:https://www.matiji.net/exam/ojquestionlist
⭐MT1558新生命
狼群新生了一只尊贵的艾尔法狼,请设计一个结构体,管理它的信息,信息包括名字,年龄,性别。
输入艾尔法狼宝宝的信息,然后再输出他的信息。
格式
输入格式:
输入名字性别为字符型,年龄整型
输出格式:
输出名字性别为字符型,年龄整型
#include<stdio.h>
struct information
{
char name[50];
int age;
char sex;
} message;
int main()
{
scanf("%s %d %c", message.name, &message.age, &message.sex);
printf("%s %d %c\n", message.name, message.age, message.sex);
return 0;
}
⭐MT1559幼儿园
幼儿园开学了,请帮老师设计一个结构体,管理宝宝们的信息,信息包括姓名,年龄,性别。
输入5个宝宝的信息,然后再输出他们的信息。
格式
输入格式:
输入分5行,姓名性别为字符型,年龄整型
输出格式:
输出1行
#include<stdio.h>
struct information
{
char name[50];
int age;
char sex;
};
int main()
{
struct information baby1;
struct information baby2;
struct information baby3;
struct information baby4;
struct information baby5;
scanf("%s %d %c", baby1.name, &baby1.age, &baby1.sex);
scanf("%s %d %c", baby2.name, &baby2.age, &baby2.sex);
scanf("%s %d %c", baby3.name, &baby3.age, &baby3.sex);
scanf("%s %d %c", baby4.name, &baby4.age, &baby4.sex);
scanf("%s %d %c", baby5.name, &baby5.age, &baby5.sex);
printf("%s %d %c ", baby1.name, baby1.age, baby1.sex);
printf("%s %d %c ", baby2.name, baby2.age, baby2.sex);
printf("%s %d %c ", baby3.name, baby3.age, baby3.sex);
printf("%s %d %c ", baby4.name, baby4.age, baby4.sex);
printf("%s %d %c ", baby5.name, baby5.age, baby5.sex);
return 0;
}
⭐MT1562谁是先锋
攻城战要开始了,女王依依手里有4个黑骑士,女王依依要找出最强大的黑骑士作为先锋。
请设计一个结构体,管理他们的信息,信息包括姓名,攻击力。
输入他们信息,然后再输出先锋的信息。
格式
输入格式:
输入分4行,姓名为字符型,攻击力整型
输出格式:
输出分4行
#include<stdio.h>
struct information
{
char name[50];
int attack_power;
};
int main()
{
struct information Knight1;
struct information Knight2;
struct information Knight3;
struct information Knight4;
scanf("%s %d", Knight1.name, &Knight1.attack_power);
scanf("%s %d", Knight2.name, &Knight2.attack_power);
scanf("%s %d", Knight3.name, &Knight3.attack_power);
scanf("%s %d", Knight4.name, &Knight4.attack_power);
if ((Knight1.attack_power > Knight2.attack_power) && (Knight3.attack_power > Knight4.attack_power))
{
if (Knight1.attack_power > Knight3.attack_power)
{
printf("%s %d", Knight1.name, Knight1.attack_power);
}
else
{
printf("%s %d", Knight3.name, Knight3.attack_power);
}
}
else if ((Knight1.attack_power < Knight2.attack_power) && (Knight3.attack_power < Knight4.attack_power))
{
if (Knight2.attack_power > Knight4.attack_power)
{
printf("%s %d", Knight2.name, Knight2.attack_power);
}
else
{
printf("%s %d", Knight4.name, Knight4.attack_power);
}
}
else if ((Knight1.attack_power > Knight2.attack_power) && (Knight3.attack_power < Knight4.attack_power))
{
if (Knight1.attack_power > Knight4.attack_power)
{
printf("%s %d", Knight1.name, Knight1.attack_power);
}
else
{
printf("%s %d", Knight4.name, Knight4.attack_power);
}
}
else if ((Knight1.attack_power < Knight2.attack_power) && (Knight3.attack_power > Knight4.attack_power))
{
if (Knight2.attack_power > Knight3.attack_power)
{
printf("%s %d", Knight2.name, Knight2.attack_power);
}
else
{
printf("%s %d", Knight3.name, Knight3.attack_power);
}
}
return 0;
}
⭐MT1563谁是胆小鬼
攻城战结束了,女王依依清点俘虏,发现跑掉了1个胆小的穴居人,女王依依要找出是谁跑掉了。斥候调查发现逃走的是一个攻击力最弱小的穴居人。
请设计一个结构体,管理穴居人俘虏的信息,信息包括姓名,攻击力。
输入4个俘虏的信息,然后再输出逃走的俘虏的信息。
格式
输入格式:
输入分4行,姓名为字符型,攻击力整型
输出格式:
输出分4行
#include<stdio.h>
struct information
{
char name[50];
int attack_power;
};
int main()
{
struct information people1;
struct information people2;
struct information people3;
struct information people4;
scanf("%s %d", people1.name, &people1.attack_power);
scanf("%s %d", people2.name, &people2.attack_power);
scanf("%s %d", people3.name, &people3.attack_power);
scanf("%s %d", people4.name, &people4.attack_power);
if ((people1.attack_power < people2.attack_power) && (people3.attack_power < people4.attack_power))
{
if (people1.attack_power < people3.attack_power)
{
printf("%s %d", people1.name, people1.attack_power);
}
else
{
printf("%s %d", people3.name, people3.attack_power);
}
}
else if ((people1.attack_power > people2.attack_power) && (people3.attack_power > people4.attack_power))
{
if (people2.attack_power < people4.attack_power)
{
printf("%s %d", people2.name, people2.attack_power);
}
else
{
printf("%s %d", people4.name, people4.attack_power);
}
}
else if ((people1.attack_power < people2.attack_power) && (people3.attack_power > people4.attack_power))
{
if (people1.attack_power < people4.attack_power)
{
printf("%s %d", people1.name, people1.attack_power);
}
else
{
printf("%s %d", people4.name, people4.attack_power);
}
}
else if ((people1.attack_power > people2.attack_power) && (people3.attack_power < people4.attack_power))
{
if (people2.attack_power < people3.attack_power)
{
printf("%s %d", people2.name, people2.attack_power);
}
else
{
printf("%s %d", people3.name, people3.attack_power);
}
}
return 0;
}
⭐MT1564编程好难
小码哥买了3本编程书,他想先学最简单的,请帮他把最薄的书挑出来。 请设计一个结构体,管理书籍的信息,信息包括种类,书名(不含空格),页数。输入书籍的信息,然后再输出最薄的书信息。
格式
输入格式:
按行输入种类,书名为字符型,价格整型文章来源:https://www.toymoban.com/news/detail-502656.html
输出格式:
按行输出种类,书名为字符型,价格整型文章来源地址https://www.toymoban.com/news/detail-502656.html
#include<stdio.h>
struct Books
{
char language[10];
char name[30];
int page;
};
int main()
{
struct Books book1;
struct Books book2;
struct Books book3;
scanf("%s %s %d", book1.language, book1.name, &book1.page);
scanf("%s %s %d", book2.language, book2.name, &book2.page);
scanf("%s %s %d", book3.language, book3.name, &book3.page);
if (book1.page < book2.page && book1.page < book3.page)
{
printf("%s %s %d", book1.language, book1.name, book1.page);
}
else if (book2.page < book1.page && book2.page < book3.page)
{
printf("%s %s %d", book2.language, book2.name, book2.page);
}
else if (book3.page < book2.page && book3.page < book1.page)
{
printf("%s %s %d", book3.language, book3.name, book3.page);
}
return 0;
}
到了这里,关于码蹄杯语言基础:结构体(C语言)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!