1702 - 2006年春浙江省计算机等级考试二级C 编程题(1)

编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(6084)和不及格(小于60)的学生人数。

运行示例:


题目输入

题目输出

输入/输出样例

题目输入

88 71 68 70 59 81 91 42 66 77 83 0

题目输出

>=85:2
60-84:7
<60:2

C语言解答

#include<stdio.h>

 

int main()

{

   int high=0,mid=0,low=0;

   int x;

   while(scanf("%d",&x), x>0)

   {

      if(x >= 85)

         high++;

      else if(x >= 60)

         mid++;

      else

         low++;

   }

   printf(">=85:%d\n60-84:%d\n<60:%d\n",high,mid,low);

 

   return 0;

}

C++解答

#include<iostream>
using namespace std;
int main()
{
	int x,a=0,b=0,c=0;
	while (cin>>x && x>0)
		if (x>=85) a++;
		else if(x>=60) b++;
		else c++;
	cout<<">=85:"<<a<<endl;
	cout<<"60-84:"<<b<<endl;
	cout<<"<60:"<<c<<endl;
	return 0;
}
时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题