编程题A-按要求输出信息
时间: 1ms 内存:128M
描述:
输出如下信息:
*****
***
*
输入:
无
输出:
按题目要求输出
示例输入:
示例输出:
*****
***
*
提示:
参考答案(内存最优[0]):
#include <iostream>
#include <cstring>
using namespace std;
struct Student
{
int no;
char name[20];
char sex[7];
int age;
int height;
};
int main()
{
int i,num=0;
struct Student stu;
for(i=0; i<10; i++)
{
cin>>stu.no;
cin>>stu.name;
cin>>stu.sex;
cin>>stu.age;
cin>>stu.height;
if(stu.age>=16&&stu.age<=19)
{
if(strcmp(stu.sex,"Female")==0)
{
if(stu.height>=160&&stu.height<=175)
num++;
}
else if(strcmp(stu.sex,"Male")==0)
{
if(stu.height>=170&&stu.height<=185)
num++;
}
}
}
cout<<num<<endl;
return 0;
}
参考答案(时间最优[0]):
#include <iostream>
#include <cstring>
using namespace std;
struct Student
{
int no;
char name[20];
char sex[7];
int age;
int height;
};
int main()
{
int i,num=0;
struct Student stu;
for(i=0; i<10; i++)
{
cin>>stu.no;
cin>>stu.name;
cin>>stu.sex;
cin>>stu.age;
cin>>stu.height;
if(stu.age>=16&&stu.age<=19)
{
if(strcmp(stu.sex,"Female")==0)
{
if(stu.height>=160&&stu.height<=175)
num++;
}
else if(strcmp(stu.sex,"Male")==0)
{
if(stu.height>=170&&stu.height<=185)
num++;
}
}
}
cout<<num<<endl;
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。
