Chicken and rabbit cage

Source: Internet
Author: User
Chicken and rabbit cage

Description

The total number of chickens and rabbits is n and the total number of legs is M. Input N and M, and output the numbers of chickens and rabbits in sequence. If there is no solution, output "No answer" (do not quote the quotation marks ).

 
Input
Input a data in the first row indicates that there are several groups of data in the next row. In the next row (A <10), each row contains N and M. (0 <m, n <100)
Output
Output The number of rabbits or no answer
Sample Input
214 3210 16
Sample output
12 2No answer

 #include<iostream> using namespace std;  int main() { int n; int a=0,b=0; int shu,leg; bool you =false; cin>>n; while(n--){     you = false;    cin>>shu>>leg;    for( a=0;a<100;a++){        for(b=0;b<100;b++){    if( (2 *a + 4 *b == leg) && (a +b == shu))          {           cout<<a<<" "<<b<<endl;         you=true;          }            }    }    if (you==false)        cout<<"No answer"<<endl; } return 0; }        

 

Chicken and rabbit cage

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.