輸入一個百分制的成績t,將其轉換成對應的等級,具體轉換規則如下:
90~100爲A;
80~89爲B;
70~79爲C;
60~69爲D;
0~59爲E;
輸入數據有多組,每組佔一行,由一個整數組成,對於每組輸入數據,輸出一行。如果輸入數據不在0~100範圍內,輸出一行:“Score is error!”
sample input:
56
67
100
123
sample output:
E
D
A
Score is error!
注意點:
在第一次過vj的時候爆了WA,是因爲忽略了輸入成績可能小於0的情況。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char func(int data)
{
data /= 10;
switch (data)
{
case(9):
return 'A';
break;
case(10):
return 'A';
break;
case(8):
return 'B';
break;
case(7):
return 'C';
break;
case(6):
return 'D';
break;
default:
return 'E';
}
}
int main()
{
int score;
while(cin>>score)
{
if(score>100||score<0)
cout<<"Score is error!"<<endl;
else
cout<<func(score)<<endl;
}
return 0;
}