#include <stdio.h>
#include <stdlib.h>
int main()
{
int score,n1=0,n2=0,n3=0,n4=0,t;
do
{
scanf("%d",&score);
t=(score>=9)+(score>=7)+(score>5);
switch (t)
{
case 0:
n1+=1;
break;
case 1:
n2+=1;
break;
case 2:
n3+=1;
break;
case 3:
n4+=1;
break;
}
}
while(score<=10);
printf("A:%d\n",n4-1);
printf("B:%d\n",n3);
printf("C:%d\n",n2);
printf("D:%d\n",n1);
return 0;
}
知识点总结:对于分情况的题来说,我比较喜欢用swich,也可能是我比较懒吧!感觉swich比连用if简单点。