已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡和兔的数目,如果无解,
则输出“No answer”(不要引号)。
import java.util.Scanner;
public class 鸡兔同笼问题 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[][]=new int[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
arr[i][j]=sc.nextInt();
}
}
for (int i = 0; i < n; i++) {
boolean a = false;
for (int j2 = 0; j2 <=arr[i][0]; j2++) {
for (int k = 0; k <=arr[i][0]; k++) {
if(((4*j2)+(2*k)==arr[i][1])&&j2+k==arr[i][0]){
System.out.println(k+" "+j2);
a=true;
}
}
}
if(a==false){
System.out.println("NO answer");
}
}
}
}
2
14 32
10 16
12 2
NO answer