习题3-2 高速公路超速处罚 (15 分)
第二个样例是卡人的,原因在于浮点数的精度问题。当我们用这种形式就能够避免第二组样例也输出“OK"的尴尬。
这里给出参考博客https://blog.youkuaiyun.com/qq_41384798/article/details/101980655
#include<stdio.h>
int main(){
int spd,dl;
scanf("%d %d",&spd,&dl);
//printf("%lf %lf\n",dl*1.1,spd);
if(spd-dl<0.1*dl)
printf("OK\n");
else if(spd-dl>=0.1*dl&&spd-dl<0.5*dl)
printf("Exceed %.0lf%%. Ticket 200",(spd-dl)*1.0/dl*100);
else if(spd-dl>=0.5*dl)
printf("Exceed %.0lf%%. License Revoked",(spd-dl)*1.0/dl*100);
return 0;
}