本文最后更新于 572 天前,其中的信息可能已经有所发展或是发生改变。
解法一:只使用if语句
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int a;
while (scanf("%d", &a) != EOF) {
if (a >= 90 && a <= 100) {
cout << "A" << endl;
}
else if (a >= 80 && a <= 89) {
cout << "B" << endl;
}
else if (a >= 70 && a <= 79) {
cout << "C" << endl;
}
else if (a >= 60 && a <= 69) {
cout << "D" << endl;
}
else if (a >= 0 && a <= 59) {
cout << "E" << endl;
}
else {
cout << "Score is error!" << endl;
}
}
return 0;
}
解法二:使用switch语句
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
char s;
while(scanf("%d",&n)!=EOF){
if(n>=80){s='a';}
if(n>=70&&n<=79){s='b';}
if(n>=60&&n<=69){s='c';}
if(n<60&&n>=0){s='d';}
if(n<0||n>100){s='e';}
switch(s){
case 'a' :
printf("A\n");break;
case 'b' :
printf("B\n");break;
case 'c' :
printf("C\n");break;
case 'd' :
printf("D\n");break;
case 'e' :
printf("E\n");break;
default :
printf("Score is error\n");break;
}
}
return 0;
}