Problem:
Simultaneous Equation

Write a program which solve a simultaneous equation:

ax + by = c

dx + ey = f

The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.

Input

The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF.

Output

For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places.

Sample Input 1

1 2 3 4 5 6
2 -1 -2 -1 -1 -5

Output for the Sample Input 1

-1.000 2.000
1.000 4.000

Sample Input 2

2 -1 -3 1 -1 -3
2 -1 -3 -9 9 27

Output for the Sample Input 2

0.000 3.000
0.000 3.000

Solution in JAVA (judge verdict: Accepted)


import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	
	static ArrayList<Double> answerX = new ArrayList<Double>();
	static ArrayList<Double> answerY = new ArrayList<Double>();
	
	public static void main(String[] args) {
				
		try{
			setAnswerFromInputs();
		}catch(NoSuchElementException e){
			//üÍÌIíèðó¯æÁÄ½àµÈ¢ÅÌÖ
		}
		
		//x,yÌoÍ
		//üÍª³íÅ êÎx,yÌðXgÌ·³Í¯¶ÈÌÅ
		//±±ÅÍXgÌ·³ð`FbNµÈ¢
		for(int i = 0; i < answerX.size(); i++){
			System.out.printf("%.3f %.3f\n", answerX.get(i), answerY.get(i));
		}
	}
	
	private static void setAnswerFromInputs() throws NoSuchElementException{
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();
			int e = sc.nextInt();
			int f = sc.nextInt();
			double x = getX(a, b, c, d, e, f);
			double y = getY(a, b, c, d, e, f);
			x = fixIncorrectNumber(x);
			y = fixIncorrectNumber(y);
			answerX.add(x);
			answerY.add(y);
		}
	}
	
	private static double getX(int a, int b, int c, int d, int e, int f){
		int denominator = a * e - b * d;
		int numerator = c * e - b * f;
		return (double)numerator / (double)denominator;
	}
	
	private static double getY(int a, int b, int c, int d, int e, int f){
		int denominator = b * d - a * e;
		int numerator = c * d - a * f;
		return (double)numerator / (double)denominator;
	}
	
	private static double fixIncorrectNumber(double x){
		if(x == (-0.0)){
			x = 0.0;
		}
		return x;
	}
}