Problem D: 鬼吹灯

做题心得:

比赛的时候做这道题,一直wa,后来认真考虑了下,有y=0的情况。

在蜡烛熄灭前离开,不能在蜡烛熄灭时。所以式子是 i=z*y/x+1。

代码:

#include<stdio.h>
#include<math.h>
int main()
{
    int x,y,z,t,i,j,k;
    while(scanf("%d",&t)!=EOF)
    {
     
    for(k=0;k<t;k++)
    {
        scanf("%d%d%d",&x,&y,&z);
        if(y==0) printf("0\n");    //一定要考虑y=0的情况 
        else{
             i=z*y/x+1;             
             printf("%d\n",i);
            }   
    }
}   
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42079027/article/details/81162021