//Autor: Bernhard Hofer
//MatNr: 0100299
//BspNr: 1118
//eMail: jans_ecleberg@yahoo.com
//Kategorie: Mathematik
//Klasse: schwer
//Eingabe: integer
//Ausgabe: float im Fixpunktf.
/* Erklaerung: Ein lineares inhomogenes Gleichungssystem von
   drei Gleichungen in drei Unbekannten soll geloest werden. */

// reformated with idea (www.intellij.com) by heder

import eprog.EprogException;
import eprog.EprogIO;

public class dreigl extends EprogIO
{
  public static void main(String[] args) throws EprogException
  {
    //die benoetigten Arrays und Variablen
    int[][] a = new int[3][4];
    int temp = 0;
    float[][] matrix = new float[3][4];
    float[][] matrix1 = new float[3][4];
    float ausgabex1 = 0;
    float ausgabex2 = 0;
    float ausgabex3 = 0;
    float umrechnungsFaktor = 0;
    boolean fehler = false;

    //Einlesen der Daten in das Array a durch eine doppelte Schleife
    for (int i = 0; i < a.length; i++)
    {
      for (int j = 0; j < a.length + 1; j++)
      {
        try
        {
          temp = readInt();
        }

                //falls ein Fehler bei der Eingabe auftritt, wird die Variable fehler = true gesetzt
        catch (EprogException e)
        {
          fehler = true;
        }

        if ((temp < 21) && (temp > -21))
        {
          a[i][j] = temp;
        }
        else
        {
          print("FALSCHE EINGABE");
          System.exit(0);
        }
      }
    }

    //Abfangen des Fehlers: wenn a11=0 werden zwei Zeilen vertauscht
    for (int j = 0; j < 2; j++)
    {
      if (a[0][0] == 0)
      {
        int puffer[] = new int[4];

        for (int i = 0; i < 4; i++)
        {
          puffer[i] = a[j + 1][i];
          a[j + 1][i] = a[0][i];
          a[0][i] = puffer[i];
        }
      }
    }

    //falls a11 immer noch 0 sein sollte, ist das Gleichungssystem nicht eindeutig loesbar
    if (a[0][0] == 0)
    {
      println("FALSCHE EINGABE");
      System.exit(0);
    }

    //Werte in der Diagonale MUESSEN ungleich 0 sein
    for (int index = 0; index < a.length; index++)
    {
      if (a[index][index] == 0)
      {
        println("FALSCHE EINGABE");
        System.exit(0);
      }
    }

    //Ueberpruefen eines Eingabefehlers durch die Variable fehler
    if (fehler == false)
    //Beginn des Algorithmus (siehe Text-File zur genaueren Erklaerung)
    {
      for (int index = 0; index < a[1].length; index++)
      {
        matrix[0][index] = a[0][index];
        matrix[1][index] = a[1][index] - (a[1][0] / (float) a[0][0]) * a[0][index];
        matrix[2][index] = a[2][index] - (a[2][0] / (float) a[0][0]) * a[0][index];
      }

      //Werte in der Diagonale MUESSEN ungleich 0 sein
      for (int index = 0; index < matrix.length; index++)
      {
        if (matrix[index][index] == 0)
        {
          println("FALSCHE EINGABE");
          System.exit(0);
        }
      }

      umrechnungsFaktor = (matrix[2][1] - (matrix[2][0] / matrix[0][0]) * matrix[0][1]) / (matrix[1][1] - (matrix[1][0] / matrix[0][0]) * matrix[0][1]);

      for (int index = 0; index < matrix[1].length; index++)
      {
        matrix1[0][index] = matrix[0][index];
        matrix1[1][index] = matrix[1][index];
        matrix1[2][index] = (matrix[2][index]) - umrechnungsFaktor * matrix[1][index];
      }

      ausgabex3 = matrix1[2][3] / matrix1[2][2];
      ausgabex2 = (matrix1[1][3] - (ausgabex3 * matrix1[1][2])) / matrix1[1][1];
      ausgabex1 = (matrix1[0][3] - (ausgabex2 * matrix1[0][1]) - (ausgabex3 * matrix[0][2])) / matrix1[0][0];

      //Werte in der Diagonale MUESSEN ungleich 0 sein
      for (int index = 0; index < matrix1.length; index++)
      {
        if (matrix1[index][index] == 0)
        {
          println("FALSCHE EINGABE");
          System.exit(0);
        }
      }

      printFixed(ausgabex1);
      print(" ");
      printFixed(ausgabex2);
      print(" ");
      printFixed(ausgabex3);
    }

    //falls ein Eingabefehler aufgetreten waere, soll eine Ausgabe "?" gemacht werden
    else
    {
      println("?");
    }

    /* Fehlerkorrektur zur Ueberpruefung des Algorithmus
    for (int index = 0; index < a.length; index++)
        {for (int index1 = 0; index1 < a[1].length; index1++)
        println(a[index][index1]);
        }
    for (int index = 0; index < matrix.length; index++)
        {for (int index1 = 0; index1 < matrix[1].length; index1++)
        println(matrix[index][index1]);
        }
    for (int index = 0; index < matrix1.length; index++)
        {for (int index1 = 0; index1 < matrix1[1].length; index1++)
        println(matrix1[index][index1]);
        }
    */
  }
}