On a judge platform, I encountered this problem, which I had wrong answer in 3 out of the 18 tests:
In the simultaneous equations
ax+by=c
dc+ey=f
x and y are unknowns. The coefficients a, b, c, d, e and f are integers. Each of the coefficients ranges from -2000 to 2000.
Write a program to read in the coefficients and solve for the unknowns of the corresponding simultaneous equations.
INPUT
The first and the only line contains six integers a, b, c, d, e and f separated by spaces.
OUTPUT
If there is exactly one solution, the first and the only line contains two numbers x and y, separated by a space, so that when they are substituted to the original equations, the set of simultaneous equations hold. If the set of simultaneous equations has no solution, display no solution
. If the set of simultaneous equations has more than one solution, display many solutions
.
Assume that x and y are always integers.
So, this is my code:
#include<bits/stdc++.h>
using namespace std;
int det(int a,int b,int c,int d){
return a*d-b*c;
}
int main(){
int a,b,c,d,e,f,det1,detx,dety;
cin >> a >> b >> c >> d >> e >> f;
det1=det(a,b,d,e);
detx=det(c,b,f,e);
dety=det(a,c,d,f);
if(det1==0){
if(detx==0){
cout << "many solutions";
}
else{
cout << "no solution";
}
}
else{
cout << detx/det1 << ' ' << dety/det1;
}
}
Can someone help me to debug this code?