Euclid's Game (simple game)

Source: Internet
Author: User
Tags time limit
Question D: Euclid's Game
Time limit: 1 Sec memory limit: MB
Submissions: 27 Resolution: 6
Submitted State [Discussion Version]
Title Description
Xiao Ming and Xiao Hong are playing Euclid's game. They start with two natural numbers, the first player xiaoming, from the larger number of two numbers minus the largest possible positive integer multiple, as long as the difference is non-negative. Then, the second player is red, to get the two number of the same operation, and then again xiaoming. In turn, the game is played, until a player will subtract a larger number from a multiple of the smaller number after the difference is 0, when the game is over, the player is the winner.
Input
The input contains multiple sets of test data. Each group enters two positive integers, which means that the game starts with two numbers, and the game is always started by Xiaoming first.
When you enter two 0, the input ends.
Output
For each set of inputs, the final winner of the output, we think that both of them are top players, each step of the game has made the best choice.
The output format is shown in the output example.
Sample input
34 12
15 24
0 0
Sample output
Xiaoming wins
Xiaohong wins
Tips

Submitted State [Discussion Version]

Problem Solving Ideas:

This is the game type of the topic, if the outcome is not doomed, then who will master the game of the initiative, that is, who ultimately wins.

Problem Solving Code:

#include <stdio.h>
int main ()
{
	int a,b,k,t;
	while (scanf ("%d%d", &a,&b), a!=0| | b!=0)
	{
		k=1;
		if (a==b)
		{
		printf ("Xiaoming wins\n");	
		}
		else
		{
			while (a!=b)
		{
			if (a<b)
			{
				t=a;
				a=b;
				b=t;
			}
			k++;
			if (a/b!=1)
			{break
					;
			} 
			
				a=a%b;
		}
		if (k%2==1)
			printf ("Xiaohong wins\n");
		else
			printf ("Xiaoming wins\n");
		}
		
	}
	return 0;
}


Error Resolution:

The same situation is not considered for the initial value of the two people.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.