zoukankan      html  css  js  c++  java
  • *循环-18. 龟兔赛跑

     1 /*
     2  * Main.c
     3  * C18-循环-18. 龟兔赛跑
     4  *  Created on: 2014年8月4日
     5  *      Author: Boomkeeper
     6  ******部分通过*******
     7  */
     8 
     9 #include <stdio.h>
    10 #include <stdlib.h>
    11 
    12 int t = 0;
    13 int distanceR = 0, distanceT = 0;
    14 //int *pdistanceR = &distanceR, *pdistanceT = &distanceT;
    15 
    16 void competition() {
    17 
    18     //兔子的控制器,如果flag=0,可以继续跑并且比较与乌龟的距离,否则直至count满30才可以继续
    19     int flag = 0, count = 0;
    20     int i;
    21     for (i = 1; i <= t; i++) {
    22 
    23         distanceT += 3;
    24 
    25         if (flag == 0) {
    26 
    27             distanceR += 9;
    28 
    29             //每10分钟兔子回头看,如果超过乌龟就休息30分钟,否则继续跑10分钟
    30             if (i % 10 == 0) {
    31                 if (distanceR > distanceT)
    32                     flag = 1;
    33                 else
    34                     continue;
    35             }
    36         }
    37 
    38         if (flag == 1) {
    39             count++;
    40             if (count == 30){
    41                 flag = 0;
    42                 count = 0;
    43             }
    44 
    45         }
    46 
    47     }
    48 }
    49 
    50 int main(void) {
    51 
    52     scanf("%d", &t);
    53     competition();
    54     if (distanceR > distanceT)
    55         printf("^_^ %d
    ", distanceR);
    56     if (distanceR < distanceT)
    57         printf("@_@ %d
    ", distanceT);
    58     if (distanceR == distanceT)
    59         printf("-_- %d
    ", distanceR);
    60     return 0;
    61 }

     

    题目链接:

    http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-18

       .

  • 相关阅读:
    17. 电话号码的字母组合
    12. 整数转罗马数字
    01-正则表达式基础
    前端SEO技巧
    node.js
    Vue.生命周期
    Vue小案例--过滤器的基本操作
    vue简单的计算器
    VSCode 自动刷新
    Vue.js学习
  • 原文地址:https://www.cnblogs.com/boomkeeper/p/C18.html
Copyright © 2011-2022 走看看