- /************************************************************************
- 龟兔赛跑
- 乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息。乌龟
- 每分钟可以前进3米,兔子每分钟前进9米;兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,
- 于是,每跑10分钟回头看一下乌龟,若发现自己超过乌龟,就在路边休息,每次休息
- 30分钟,否则继续跑10分钟;而乌龟非常努力,一直跑,不休息。假定乌龟与兔子在
- 同一起点同一时刻开始起跑,请问T分钟后乌龟和兔子谁跑得快?
- 输入格式:
- 输入在一行中给出比赛时间T(分钟)。
- 输出格式:
- 乌龟赢输出“@_@”,兔子赢输出“^_^”,平局则输出“-_-”;后跟1空格,再输出
- 胜利者跑完的距离。
- 输入样例:
- 242
- 输出样例:
- @_@ 726
- ************************************************************************/
- #include <stdio.h>
- int main(void) {
- int t;
- int i;
- int sum_tuzi = 0,
- sum_wugui = 0;
- int stopflag = 0; // 0:Not stopping,1:stopping
- int tmr_cnt;
- scanf ("%d", &t);
- for (i=1; i<=t; i++) {
- sum_wugui += 3;
- if (stopflag == 0) { // Not stopping
- sum_tuzi += 9;
- if (i%10==0) {
- if ( sum_tuzi > sum_wugui ) {
- stopflag = 1;
- tmr_cnt = 30;
- }
- }
- } else { // stopping
- tmr_cnt--;
- if (tmr_cnt == 0) {
- stopflag = 0; // Not stopping
- }
- }
- }
- if (sum_wugui == sum_tuzi) {
- printf ("-_- %d\\n", sum_tuzi);
- } else {
- sum_wugui > sum_tuzi ? printf ("@_@ %d\\n", sum_wugui) : \\
- printf ("^_^ %d\\n", sum_tuzi);
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1712201411301.html
来源: http://www.codesnippet.cn/detail/1712201411301.html