7-9 Tortoise and the Hare (20 points)

7-9 Tortoise and the Hare (20 points)

The tortoise races with the rabbit. The running field is a rectangular track, and you can rest anywhere on the side of the track. The tortoise can advance 3 meters per minute, and the hare can advance 9 meters per minute; the hare thinks that the tortoise runs slowly and thinks that it will definitely outperform the tortoise. So, every 10 minutes you run, look back at the tortoise. Rest, rest for 30 minutes at a time, otherwise continue to run for 10 minutes; while the tortoise works very hard and runs without rest. Assuming that the tortoise and the hare start to run at the same starting point and at the same time, after T minutes, which of the tortoise and hare will run fast?

Input format:
Enter the game time T (minutes) in one line.

Output format:
output the result of the game in one line: the tortoise wins the output @ @, the rabbit wins the output _ , and the tie is output-- ; followed by 1 space, and then output the distance the winner ran.

Input sample:
242
Output sample:
@_@ 726

c language:

#include<stdio.h>
int main()
{
    
    
	int t,i,j=0,sleep=0,tz=0,wg=0,flag=0;
	scanf("%d",&t);
	for(i=1;i<=t;i++)
	{
    
    
		if(flag==1) 
		{
    
    
			sleep++;
			if(sleep==30) flag=0;
		}
		else 
		{
    
    
			j++;
			tz=tz+9;
			if(j==10)
			{
    
    
				if(tz>wg)
				{
    
    
					flag=1;
					sleep=0;
				}
				j=0;
			}
		}
		wg=wg+3;
	}
	if(wg==tz) printf("-_- %d\n");
	else if(tz<wg) printf("@_@ %d\n",wg);
	else printf("^_^ %d\n",tz);
	return 0;
}

Java:

待更新

Guess you like

Origin blog.csdn.net/xiahuayong/article/details/109055765