The tortoise and the Rabbit race, the running field is a moment-type runway, the runway side can rest everywhere. Turtle can advance 3 meters per minute, the rabbit forward 9 meters per minute, the hare too slow to run, feel sure can run to win the Turtle, so, every 10 minutes to look back at the turtle, if found himself over the turtle, on the roadside rest, every rest 30 minutes, or continue to run 10 minutes; Suppose the tortoise and the Hare start at the same time at the same starting point, may I ask the tortoise and the rabbit to run fast after T minute?
Input format:
Enter the race time t (minutes) in a row.
Output format:
Output the result of the match in one row: The Turtle wins the output "@[email protected]", the Rabbit wins output "^_^", the draw output "-_-", followed by 1 spaces, and then output the winner run out of distance.
Input Sample:
242
Sample output:
@[email protected] 726
#include <iostream> #include <stdio.h> #include <math.h> #include <string>int main () {int t; scanf ("%d", &t); int i=0;int rabbit=0;int tortoise=0;int wait=30;int run=10;int mode=0; while (i<t) {i++; tortoise+=3; if (mode==0)//rabbit is in run mode {if (run>0) {rabbit+=9; run--; printf ("Run%d Rabbit%d tortoise%d\n", run,rabbit,tortoise);} else//10 minutes to {if (rabbit>tortoise)//detect whether beyond {mode=1;//beyond the rest of the wait=29; printf ("Wait%d rabbit%d tortoise%d\n", wait,rabbit,tortoise); } else//not go beyond, continue to run {mode=0; run=9; rabbit+=9; printf ("Run%d Rabbit%d tortoise%d\n", run,rabbit,tortoise); }}}else {if (wait>0) {wait--;//rest//printf ("Wait%d rabbit%d tortoise%d\n", wait,rabbit,tortoise);} else{mode=0;run=9;rabbit+=9;//printf ("Run%d Rabbit%d tortoise%d\n", run,rabbit,tortoise);}} } if (rabbit>tortoise) printf ("^_^%d", rabbit); else if (rabbit==tortoise) printf ("-_-%d", rabbit); else printf ("@[email pRotected]%d ", tortoise); return 0;}
Cycle-18. Turtle and Rabbit Race (20)