题解 B2131 【甲流病人初筛】
思路
- 使用计数器
ans 来记录被初筛为甲流的病人数量; - 依次读入病人的信息,判断此人体温是否大于等于
37.5 度且咳嗽,如果是的话,直接输出病人名字,ans ++; - 最后输出
ans 。
Code
#include<bits/stdc++.h>
using namespace std;
int n,cough,ans;
string name; //循环n次读入,可以重复使用变量
double temp;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>name>>temp>>cough; //读入病人的信息
if(temp>=37.5&&cough) //如果符合筛查条件
{
cout<<name<<endl; //输出名字
ans++; //被初筛为甲流的病人数量+1
}
}
cout<<ans<<endl; //输出被初筛为甲流的病人数量
return 0;
}