题目描述
输入两个整数代表鸡和兔的总只数与总脚数,编写程序,输出鸡和兔各多少只(输入和输出时,按先鸡后免的顺序,中间以空格分隔)。
输入格式
两个不超过100000的非负整数,以空格分隔。
输出格式
两个整数,以空格分隔,若输入数据无解,输出:-1 -1(表示无可能)。
输入样例1
在这里给出一组输入。例如:
10
28
输出样例1
在这里给出相应的输出。例如:
6
4
输入样例2
在这里给出一组输入。例如:
18
35
输出样例2
在这里给出相应的输出。例如:
-1 -1
package com.ty.java;
import java.util.Scanner;
public class Height{
public static void main(String[] args) {
int a,b,x,y;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
x=(a*4-b)/2;
y=a-x;
if (x == a &&y == 0){
System.out.println("-1 -1");
}
else {
System.out.println(x);
System.out.println(y);
}
}
}
代码运行如下:
com.ty.java.Height
10
28
6
4
Process finished with exit code 0
com.ty.java.Height
18
35
-1 -1
Process finished with exit code 0