这个题有点意思,是解一个二元一次方程,手算很简单,但是怎么用算法来解还真没想过,一下子好像也没什么思路
import java.util.*;
import java.io.*;
class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
int milk = Integer.parseInt(tokenizer.nextToken());
int tea = Integer.parseInt(tokenizer.nextToken());
double x = (milk-tea)/10.0;
double y = (3*tea-milk)/20.0;
if(x>=0&&y>=0&&x%1==0&&y%1==0){
System.out.print((int)x+" "+(int)y);
}else {
System.out.println(-1);
}
}
}
边界条件首先是都为0的情况要包含,另外注意这个除运算要用double丢失精度,后面才能做是否为整的判断,但是输出的时候又要把这个精度转回来,不然判断不过
标签:Java,tokenizer,int,tea,System,3184,2020,&&,milk From: https://www.cnblogs.com/yaocy/p/16864700.html