龜兔賽跑
阿新 • 來源:網路 • 發佈:2021-02-15
技術標籤:C
1、題目

#include<stdio.h>
#include <stdlib.h>
int main()
{
int min;
scanf("%d", &min);
int s1 = 0, s2 = 0, run = 10, rest = -1;
while (min--)
{
//烏龜的速度
s1 += 3;
if (run-- > 0)
{
//兔子的速度
s2 += 9;
}
//達到10分鐘之後,兔子回頭的計算方式
if (run == 0)
{
if (s2 > s1 &&rest != 0)
{
//休息30分鐘
rest = 30;
}
else
{
run = 10;
}
}
//休息完了,重置回來
if (rest-- == 0)
{
run = 10;
}
}
if (s1 > s2)
{
printf("@[email protected] %d", s1);
}
else if (s1 < s2)
{
printf("^_^ %d", s2);
}
else
{
printf("-_- %d", s2);
}
system("pause");
return 0;
}
