hdu_2004_成绩转换_解题报告

题目出处

简单题

思路:

这题应该是学习后C的 switch if-else-if 语法后经常做的题目类型

所以此题用上述两种分支语句都能解题,而初学者可能多数这样做:

if (input > 100 || input < 0)
{
	printf("Score is error!\n");
}
else if (input >= 90 && input <= 100)
	printf("A\n");
else if (input >= 80 && input < 90)
	printf("B\n");
else if (input >= 70 && input < 80)
	printf("C\n");
else if (input >= 60 && input < 70)
printf("D\n");
else if (input >= 0 && input < 60)
	printf("E\n");

其实仔细观察后,只要按一定的顺序,判断语句就可以简短一些,并且这里使用 puts() 效率会比printf() 要高效和简洁

关键代码:

 if (input < 0)
            puts("Score is error!");
        else if (input < 60)
            puts("E");
        else if (input < 70)
            puts("D");
        else if (input < 80)
            puts("C");
        else if (input < 90)
            puts("B");
        else if (input <= 100)
            puts("A");
        else
            puts("Score is error!");



原文地址:https://www.cnblogs.com/xinyuyuanm/p/2999132.html