C language implementation for athletes diving rankings

Source: Internet
Author: User

C language implementation for athletes diving rankings
Five athletes participated in the 10-meter diving competition. Some people asked them to predict the results. Contestant A said: B is the first, I am the third. Contestant B said: I am second, E is fourth. Contestant C said: I am the first, and D is the second. Contestant D said: "C, I am the third. Contestant E said: I am the fourth, A is the first. After the competition, each contestant is half right. Please program to determine the ranking of the competition. Code implementation:

#include <stdio.h>int main(){ int a=0,b=0,c=0,d=0,e=0; int flag=0; int ret=0; 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((1==(b==1)+(a==3))&&         (1==(b==2)+(e==4))&&         (1==(c==1)+(d==2))&&         (1==(c==5)+(d==3))&&         (1==(e==4)+(a==1)))      {       flag=0;       ret=0;       ret|=(1<<(a-1));       ret|=(1<<(b-1));       ret|=(1<<(c-1));       ret|=(1<<(d-1));       ret|=(1<<(e-1));       while(ret)       {        if(ret%2==0)        {         flag=1;         break;        }        ret/=2;                }       if(flag==0)        {         printf("a=%d b=%d c=%d d=%d e=%d\n",a,b,c,d,e);        }      }     }    }   }  } } return 0;}

 

Result: a = 2 B = 1 c = 1 d = 3 e = 4

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.