C Language: 2 ways: 5 athletes participate in the diving competition, each player is said to half, please determine the position of the match

Source: Internet
Author: User

5 athletes participated in the ten - metre diving competition, where they were asked to predict the outcome of the match .

A contestant said:B First, I third.

B contestant said: I second,E fourth.

C contestant said: I first,D second.

D contestant said:C Finally, I third.

E contestant said: I am four,A first.

After the game is over, each player is half right, please program to determine the position of the match.

Program One:

#include <stdio.h>

int Main ()

{

int a = 1, b = 1,c = 1,d=1,e=1;

for (a = 1; a <= 5; a++)

{

for (b = 1; b <= 5; b++)

{

for (c = 1; C <= 5; C + +)

{

for (d = 1; d <= 5; d++)

{

for (e = 1; e <= 5; e++)

{

if  ((b = = 1) + (A = = 3) = = 1 && (b = = 2) + (E = = 4) = = 1 && (c = = 1) + (d = = 2) = = 1 && (c = = 5) + (d = = 3) = = 1 && (e = = 4) + (A = = 1) = = 1)

{

printf ("a=%d\nb=%d\nc=%d\nd=%d\ne=%d\n", a,b,c,d,e);

return 0;

}

}

}

}

}

}

return 1;

}

Program Two:

#include <stdio.h>

int Main ()

{

int a = 1, b = 1, c = 1, d = 1, E = 1;

for (a = 1; a <= 5; a++)

{

for (b = 1; b <= 5; b++)

{

for (c = 1; C <= 5; C + +)

{

for (d = 1; d <= 5; d++)

{

for (e = 1; e <= 5; e++)

{

if  ((b = = 1) + (A = = 3) = = 1 && (b = = 2) + (E = = 4) = = 1 && (c = = 1) + (d = = 2) = = 1 && (c = = 5) + (d = = 3) = = 1 && (e = = 4) + (A = = 1) = = 1)

{

int num = 0;

num |= (1 << (A-1)); //binary continuous set to 1,11111 respectively indicates that the number between 1,2,3,4,5 can be stored continuously

Num |= (1 << (b-1));

Num |= (1 << (c-1));

Num |= (1 << (d-1));

Num |= (1 << (e-1));

while (num)

{

if (num% 2 = = 0) //binary 1 is continuous, can not be divisible by 2, if divisible, indicating that there are 0 in the binary

{

Break ;

}

num = NUM/2;

}

if (num = = 0)

{

printf ("a=%d\nb=%d\nc=%d\nd=%d\ne=%d\n", A, B, C, D, e);

}

}

}

}

}

}

}

return 0;

}

Results:

a=2

B=1

C=1

D=3

E=4

Please press any key to continue ...


This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1725457

C Language: 2 ways: 5 athletes participate in the diving competition, each player is said to half, please determine the position of the match

Related Article

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.