c语言编程练习题:7-39 龟兔赛跑
作者:yunjinqi   类别:    日期:2023-05-29 14:17:57    阅读:478 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    int T;
    int distance_rabbit=0,distance_turtle=0;
    //int speed_rabbit = 9,speed_turtle=3;
    int need_sleep=0;
    int i;
    if (scanf("%d",&T)!=0){
        //根据具体的时间进行循环
        //printf("T=%d",T);
        for (i=1;i<=T;i++){
            distance_turtle+=3;
            if (need_sleep==0){distance_rabbit+=9;}
            if (need_sleep>=1){need_sleep-=1;}
            //printf("i=%d need_sleep=%d distance_rabbit=%d distance_turtle=%d\n",i,need_sleep,distance_rabbit,distance_turtle);
            // 如果当前时间是十分钟间歇,并且兔子超过乌龟,兔子开始休息
            if (need_sleep==0 && i%10==0){
                if (distance_rabbit>distance_turtle){need_sleep=30;}
            }
        }
        // 判断是谁赢了
        if (distance_rabbit>distance_turtle){printf("^_^ %d",distance_rabbit);}
        if (distance_rabbit<distance_turtle){printf("@_@ %d",distance_turtle);}
        if (distance_rabbit==distance_turtle){printf("-_- %d",distance_rabbit);}
    }else{
        printf("something wrong");
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/164
上一篇:c语言编程练习题:7-38 支票面额
下一篇:c语言编程练习题:7-40 到底是不是太胖了