-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.4.1.cpp
More file actions
47 lines (44 loc) · 897 Bytes
/
4.4.1.cpp
File metadata and controls
47 lines (44 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <iostream>
#include <assert.h>
typedef const double db;
using namespace std;
//只输出又一个解的情况
void solve(db a,db b,db d,db e,double *x,double *y)
{
//如果不是只有一个解
assert(a*e-b*d!=0)
*x = (c*e-b*f)/(a*e-b*d);
*y = (c*d-a*f)/(b*d-a*e);
return;
}
//引入标志,进行区别到底有多少个解
void solve(db a,db b,db d,db e,double *x,double *y)
{
int flag = 1;
if(a*e-b*d!=0)
{
*x = (c*e-b*f)/(a*e-b*d);
*y = (c*d-a*f)/(b*d-a*e);
}
else if(c*e-b*f==0)
flag = 0;
else if(c*e-b*f!=0)
flag = -1
}
int main()
{
double a,b,c,d,e,f;
double x,y = 0;
scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);
slove(a,b,c,d,e,f,&x,&y);
printf("x = %.2lf\ny = %.2lf\n",x,y);
slove1(a,b,c,d,e,f,&x,&y);
if(flag == 1)
printf("one result:x = %.2lf\ny = %.2lf\n",x,y);
else if(flag ==0)
printf("Unlimited answers");
else
printf("No answer");
return 0;
}