PTA brushing notes (C language) | 7-39 Turtle-Rabbit Race (20 points)

Start brushing questions, I feel that the amount of code and the foundation are too scum, resulting in the data structure will not, slowly brush it ~
Insert picture description here


1. Title

Insert picture description here
Sample input:

242

Sample output:

@_@ 726


2. Code

#include<stdio.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;
		}
		if(run==0){
			if(s2>s1&&rest!=0){
				rest=30;
			}
			else{
				run=10;
			}
		}
		if(rest--==0){
			run=10;
		}
	}
	if(s1>s2){
		printf("@_@ %d",s1);
	}
	else if(s1<s2){
		printf("^_^ %d",s2);
	}
	else{
		printf("-_- %d",s2);
	}
	
	return 0;
}

Insert picture description here

3 Discussion

This question is very interesting. You have to find a variable to measure this relationship. The time is indeed better, but the tearing time is not particularly good. Simulate the natural time, so that the process of the turtle-rabbit race can be better written. .

Define two variables, one runand one rest, to realize the process of exercise and rest. If it is used up, re-grant it. Every ten minutes after the rabbit runs, you need to verify who is running fast with the turtle. If you are not taking a break at the same time, then rest for 30 minutes. If the break is over, then run for ten minutes.

Wonderful! ! !
Insert picture description here
Insert picture description here

Published 257 original articles · praised 5220 · 880,000 views

Guess you like

Origin blog.csdn.net/TeFuirnever/article/details/105536781