程序:
#include <stdio.h> int main () { int rabbit=,turtle=,minute,rest=-,run=; //rest为0或负时,兔子休息,run为1-10是兔子跑
scanf ("%d",&minute) ; while(minute--){
turtle += ;
if (run-- > )
rabbit += ;
if (run == ){ //兔子跑10分钟回头看一下,如果比乌龟快就休息30分钟,反之再跑10分钟
if (rabbit > turtle)
rest = ;
else run = ;
}
if (rest-- == ) //休息结束继续跑10分钟
run = ;
}
//printf("rabbit=%d,turtle=%d\n",rabbit,turtle);
if(turtle > rabbit)
printf("@_@ %d",turtle);
else if (rabbit > turtle)
printf("^_^ %d",rabbit);
else
printf("-_- %d",rabbit); return ;
}
我的程序:
#include<stdio.h>
int main() {
int sleep=,clock=-,T,t=,s1=,s2=;
scanf("%d",&T);
while(T--){
if(sleep== && clock==) sleep = ; //闹钟响,起床
if(t%== && sleep== && s2>s1){
sleep = ;//睡觉
clock = ;//闹钟
}
s1 += ;
if(sleep==) s2 += ;//不睡就跑
if(sleep==) clock--;
t++;
}
if(s1>s2) printf("@_@ %d",s1);
else if(s2>s1) printf("^_^ %d",s2);
else printf("-_- %d",s1);
}
几个细节要考虑清楚:
1、t从0开始
2、while循环中是1s中发生的事情,按先后次序执行
3、sleep:睡觉状态,clock:计时