Skip to content

Instantly share code, notes, and snippets.

@listopad
Created December 26, 2019 13:02
Show Gist options
  • Save listopad/96493f067f6d7e3675fefd873cf1102f to your computer and use it in GitHub Desktop.
Save listopad/96493f067f6d7e3675fefd873cf1102f to your computer and use it in GitHub Desktop.
Задача D
private static void SolveLinearEquations(int a, int b, int c, int d, int e, int f) {
float D = a * d - c * b;
float Dx = e * d - f * b;
float Dy = a * f - c * e;
if (D != 0) {
// решение единственное
float x = Dx / D;
float y = Dy / D;
System.out.print(2 + " ");
System.out.printf("%.2f", x);
System.out.print(" ");
System.out.printf("%.2f", y);
} else {
if (Math.abs(a) + Math.abs(b) + Math.abs(c) + Math.abs(d) == 0)
if (Math.abs(e) + Math.abs(f) == 0) {
// любая пара
System.out.println("2XY");
} else {
// решений нет
System.out.println(0);
}
else {
if (Dx != 0 || Dy != 0) {
System.out.println(0);
} else if (b == 0) {
System.out.print("1Y ");
System.out.printf("%.2f", (float) e / a);
} else if (a == 0) {
System.out.print("1X ");
System.out.printf("%.2f", (float) e / b);
} else
System.out.println(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment