成績轉(zhuǎn)換 Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 139257 Accepted Submission(s): 60697
輸入一個百分制的成績t,將其轉(zhuǎn)換成對應(yīng)的等級,具體轉(zhuǎn)換規(guī)則如下: 90~100為A; 80~89為B; 70~79為C; 60~69為D; 0~59為E;
Input
輸入數(shù)據(jù)有多組,每組占一行,由一個整數(shù)組成。
Output
對于每組輸入數(shù)據(jù),輸出一行。如果輸入數(shù)據(jù)不在0~100范圍內(nèi),請輸出一行:“Score is error!”。
Sample Input
56 67 100 123
Sample Output
E D A Score is error!
本題用if else 語句也可以,但是沒有switch語句簡潔明了。
#include <stdio.h>#include <stdlib.h>/*90~100為A;80~89為B;70~79為C;60~69為D;0~59為E;/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) { int r; while(scanf("%d",&r)!=EOF) { if(r>100||r<0) { printf("Score is error!/n"); continue; } switch(r/10) { case 10:; case 9:printf("A/n");break; case 8:printf("B/n");break; case 7:printf("C/n");break; case 6:printf("D/n");break; default:printf("E/n");break; } } return 0;}新聞熱點
疑難解答