码迷,mamicode.com
首页 > 其他好文 > 详细

*循环-18. 龟兔赛跑

时间:2014-08-19 23:52:25      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

 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\n", distanceR);
56     if (distanceR < distanceT)
57         printf("@_@ %d\n", distanceT);
58     if (distanceR == distanceT)
59         printf("-_- %d\n", distanceR);
60     return 0;
61 }

 bubuko.com,布布扣

题目链接:

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

 

 

 

 

   .

*循环-18. 龟兔赛跑,布布扣,bubuko.com

*循环-18. 龟兔赛跑

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/boomkeeper/p/C18.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!