问题:
C:刑警的射击成绩
Description
刑警培训结束,进行了射击科检验。教官要对学员射击的成绩进行分析,得出各分数段人数统计。
Input
输入若干个0-10间的整数(最高10环,脱靶为0)表示成绩,人数不确定,输入以一个0-10以外的数作为。
Output
各分数段(A:9环以上,B:7环以上,C:5环以上,D:不足5环)的人数,每项成绩占一行
Sample Input
9 7 3 5 8 5 6 7 9 10 0 6 99
Sample Output
A:3
B:3
C:4
D:2
代码:
#include<iostream>
using namespace std;
int main()
{
int x,A=0,B=0,C=0,D=0;
while((cin>>x)&&!(x>10||x<0)) //完成多次输入,同时进行判断。
{
switch(x)
{
case 0:
case 1:
case 2:
case 3:
case 4:D++;break;
case 5:
case 6:C++;break;
case 7:
case 8:B++;break;
case 9:
case 10:A++;
}
}
cout<<"A:"<<A<<endl;
cout<<"B:"<<B<<endl;
cout<<"C:"<<C<<endl;
cout<<"D:"<<D<<endl;
return 0;
}
运行结果:
知识点总结:
第三种输入形式,在输入的时候同时进行判断,在遇到一个特殊值的时候结束程序