标签:style blog ar color os sp java for on
描述已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡和兔的数目,如果无解,则输出“No answer”(不要引号)。
2
14 32
10 16
12 2
No answer
1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main { 5 public static void main(String[] args) { 6 Scanner scanner=new Scanner(System.in); 7 int T; 8 int k; 9 int n; 10 int m; 11 12 T=scanner.nextInt(); 13 for(k=0;k<T;k++){ 14 n=scanner.nextInt(); 15 m=scanner.nextInt(); 16 17 if(m>=2*n && (m-2*n)%2==0 && 4*n>=m && (4*n-m)%2==0) 18 System.out.println((4*n-m)/2+" "+(m-2*n)/2); 19 20 else 21 System.out.println("No answer"); 22 } 23 } 24 }
标签:style blog ar color os sp java for on
原文地址:http://www.cnblogs.com/zqxLonely/p/4130746.html