一、题面题目来自 【 PTA 520 钻石争霸赛 2022 】
二、代码实现 C语言输入格式:在 520 这个日子里,没有比开发一个约会 App 更合适做的事情了。这个软件的需求很简单,用户输入自己的性别、想要约会的异性的年龄范围 [a,b]、身高范围 [c,d],你要帮用户筛选出系统中满足其约会条件的所有异性。注意:性别、年龄、身高的要求必须全都符合要求才可以。
输出格式:输入第一行首先给出一个用户自己输入的信息,格式如下:
c 性别 a b c d
其中 性别 为 0 表示女性,1 表示男性,是该用户自己的性别;后面四个数字依次表示该用户想要约会的异性的年龄下限、年龄上限、身高下限、身高上限 ——
注意这里的范围都是闭区间。随后一行给出一个正整数 N≤100,随后 N 行,每行给出一位系统中登记的约会对象的信息,格式如下:
c 性别 年龄 身高
这里保证年龄和身高(包括上、下限)均为不超过 200 的正整数,同行数字间以 1 个空格分隔。
输入样例:按照输入的顺序,输出每个满足用户约会条件的约会对象的信息,输出格式与输入格式相同。题目保证至少有一个人可以被输出。
1 20 25 160 175
输出样例:
6
0 28 165
1 21 170
0 25 160
0 22 180
1 20 175
0 20 1750 25 160
0 20 175|代码长度限制|16 KB| |时间限制|400 ms| |内存限制|64 MB|
#includestruct STU{ int id; //xing bie int age; //nian ling int hight; //shen gao }; int main() { int sex,a,b,c,d; int id,i,cnt=0; struct STU stu[100]; struct STU yue[100]; scanf("%d %d %d %d %d",&sex,&a,&b,&c,&d); scanf("%d",&id); for(i=0;i scanf("%d %d %d",&stu[i].id,&stu[i].age,&stu[i].hight); if(stu[i].id+sex==1) if(a<=stu[i].age && stu[i].age<=b) if(c<=stu[i].hight && stu[i].hight<=d) { yue[cnt].id = stu[i].id; yue[cnt].age = stu[i].age; yue[cnt].hight = stu[i].hight; cnt++; } } for(i=0;i printf("%d %d %dn",yue[i].id,yue[i].age,yue[i].hight); } printf("%d %d %d",yue[i].id,yue[i].age,yue[i].hight); return 0; }



