import java.io.*;
import java.util.*;
import java.math.*;
class Main {
final static String filename
= "renritsu.txt"; public static void main
(String args
[]){ double[][] A = null;
//read from data
try {
int rows = 0, cols = 0;
while((s = br.readLine()) != null){
vals = s.split(" ");
cols
= Math.
max(cols, vals.
length); rows++;
}
System.
out.
println(rows
+"×"+cols
+" array found"); A = new double[rows][cols];
br.close();
rows = cols = 0;
while((s = br.readLine()) !=null){
vals =s.split(" ");//split the line with space
cols = vals.length;
for(int i=0; i<cols;i++)
A
[rows
][i
]=Double.
parseDouble(vals
[i
]); rows++;
}
}
dump(A);
//forward
for(int i = 0; i< A.length ;i++) {
double P = A[i][i];//pivot
for(int j = 0; j < A[i].length; j++)
A[i][j] /= P;
for (int j = i + 1; j < A.length; j++) {
P = A[j][i];
if (Math.
abs(P
) > 0.0001) { for(int k = 0; k < A.length; k++) {
double v = A[k][i];
A[j][k] /= P;
A[j][k] -= A[i][k];
}
}
}
}
dump(A);
//backward
for(int i = A.length - 1; i >= 0; i--)
for (int j = i - 1; j >= 0; j--) {
A[j][A.length] -= A[j][A.length] * A[j][i];
A[j][i] = 0.0;
}
dump(A);
}
static void dump(double[][] a) {
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++)
System.
out.
printf("%6.3f ", a
[i
][j
]); }
}
}
/* end */
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5tYXRoLio7CmNsYXNzIE1haW4gewogIGZpbmFsIHN0YXRpYyBTdHJpbmcgZmlsZW5hbWUgPSAicmVucml0c3UudHh0IjsKICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcgYXJnc1tdKXsKICAgIFN5c3RlbS5vdXQucHJpbnRsbigic3RhcnQuIik7CiAgICBkb3VibGVbXVtdIEEgPSBudWxsOwoKICAgIC8vcmVhZCBmcm9tIGRhdGEKICAgIHRyeSB7CiAgICAgIEJ1ZmZlcmVkUmVhZGVyIGJyID0gbmV3IEJ1ZmZlcmVkUmVhZGVyKG5ldyBGaWxlUmVhZGVyKGZpbGVuYW1lKSk7CiAgICAgIFN0cmluZyBzOwogICAgICBTdHJpbmdbXSB2YWxzOwogICAgICBpbnQgcm93cyA9IDAsIGNvbHMgPSAwOwogICAgICB3aGlsZSgocyA9IGJyLnJlYWRMaW5lKCkpICE9IG51bGwpewogICAgICAgIHZhbHMgPSBzLnNwbGl0KCIgIik7CiAgICAgICAgY29scyA9IE1hdGgubWF4KGNvbHMsIHZhbHMubGVuZ3RoKTsKICAgICAgICByb3dzKys7CiAgICAgIH0KICAgICAgU3lzdGVtLm91dC5wcmludGxuKHJvd3MrIsOXIitjb2xzKyIgYXJyYXkgZm91bmQiKTsKICAgICAgQSA9IG5ldyBkb3VibGVbcm93c11bY29sc107CiAgICAgIGJyLmNsb3NlKCk7CgogICAgICBiciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgRmlsZVJlYWRlcihmaWxlbmFtZSkpOwogICAgICByb3dzID0gY29scyA9IDA7CiAgICAgIHdoaWxlKChzID0gYnIucmVhZExpbmUoKSkgIT1udWxsKXsKICAgICAgICB2YWxzID1zLnNwbGl0KCIgIik7Ly9zcGxpdCB0aGUgbGluZSB3aXRoIHNwYWNlCiAgICAgICAgY29scyA9IHZhbHMubGVuZ3RoOwogICAgICAgIGZvcihpbnQgaT0wOyBpPGNvbHM7aSsrKQogICAgICAgICAgQVtyb3dzXVtpXT1Eb3VibGUucGFyc2VEb3VibGUodmFsc1tpXSk7CiAgICAgICAgcm93cysrOwogICAgICB9CiAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBlKXsKICAgICAgU3lzdGVtLm91dC5wcmludGxuKGUpOwogICAgfQogICAgZHVtcChBKTsKCiAgICAvL2ZvcndhcmQKICAgIGZvcihpbnQgaSA9IDA7IGk8IEEubGVuZ3RoIDtpKyspIHsKICAgICAgZG91YmxlIFAgPSBBW2ldW2ldOy8vcGl2b3QKICAgICAgZm9yKGludCBqID0gMDsgaiA8IEFbaV0ubGVuZ3RoOyBqKyspCiAgICAgICAgQVtpXVtqXSAvPSBQOwogICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCBBLmxlbmd0aDsgaisrKSB7CiAgICAgICAgUCA9IEFbal1baV07CiAgICAgICAgaWYgKE1hdGguYWJzKFApID4gMC4wMDAxKSB7CiAgICAgICAgICBmb3IoaW50IGsgPSAwOyBrIDwgQS5sZW5ndGg7IGsrKykgewogICAgICAgICAgICBkb3VibGUgdiA9IEFba11baV07CiAgICAgICAgICAgIEFbal1ba10gLz0gUDsKICAgICAgICAgICAgQVtqXVtrXSAtPSBBW2ldW2tdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogICAgZHVtcChBKTsKCiAgICAvL2JhY2t3YXJkCiAgICBmb3IoaW50IGkgPSBBLmxlbmd0aCAtIDE7IGkgPj0gMDsgaS0tKQogICAgICBmb3IgKGludCBqID0gaSAtIDE7IGogPj0gMDsgai0tKSB7CiAgICAgICAgQVtqXVtBLmxlbmd0aF0gLT0gQVtqXVtBLmxlbmd0aF0gKiBBW2pdW2ldOwogICAgICAgIEFbal1baV0gPSAwLjA7CiAgICAgIH0KICAgIGR1bXAoQSk7CiAgfQogIHN0YXRpYyB2b2lkIGR1bXAoZG91YmxlW11bXSBhKSB7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgYS5sZW5ndGg7IGkrKykgewogICAgICBmb3IoaW50IGogPSAwOyBqIDwgYVtpXS5sZW5ndGg7IGorKykKICAgICAgICBTeXN0ZW0ub3V0LnByaW50ZigiJTYuM2YgIiwgYVtpXVtqXSk7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigpOwogICAgfQogICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgfQp9Ci8qIGVuZCAqLwo=