Chicken and rabbit cage

Source: Internet
Author: User

Describes the total number of chickens and rabbits known to be n and the total number of legs m. Enter n and m, output the number of chickens and rabbits in turn, and if no solution, output "no answer" (no quotation marks).

 
Input
The
first line enters a data A, representing the next few sets of data, in the next (a<10)
in line A, each row has an N and M. (0<m,n<100)
Output
output the number of chicken rabbits, or no answer
Sample input
214 3210 16
Sample output
2No Answer

1 Importjava.util.Arrays;2 ImportJava.util.Scanner;3 4  Public classMain {5      Public Static voidMain (string[] args) {6Scanner scanner=NewScanner (system.in);7         intT;8         intK;9         intN;Ten         intm; One          At=scanner.nextint (); -          for(k=0;k<t;k++){ -n=scanner.nextint (); them=scanner.nextint (); -              -             if(M>=2*n && (m-2*n)%2==0 && 4*n>=m && (4*n-m)%2==0) -System.out.println ((4*n-m)/2+ "" + (M-2*n)/2); +              -             Else +System.out.println ("No answer"); A         }     at     }     -}

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.