蓝桥杯 算法提高VIP 解二元一次方程组(Java解题)

【题目来源】:解二元一次方程组

【题目描述】:

给定一个二元一次方程组,形如: 
a  *  x  +  b  *  y  =  c; 
d  *  x  +  e  *  y  =  f; 
x,y代表未知数,a,  b,  c,  d,  e,  f为参数。 
求解x,y 

数据规模和约定 
0  < =  a,  b,  c,  d,  e,  f  < =  2147483647 

输入
输入包含六个整数:  a,  b,  c,  d,  e,  f; 
输出
输出为方程组的解,两个整数x,  y。 
样例输入
3  7  41  2  1  9 
样例输出
2 5

【解析】:很简单的一道数学题目,题目描述的不太清楚,不用考虑分母为0的情况

【代码】:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int e=sc.nextInt();
		int f=sc.nextInt();
		System.out.println((c*e-b*f)/(a*e-b*d)+" "+(c*d-a*f)/(b*d-a*e));
	}
}