include iostream include cstdlib include fstream include clocale inclu

 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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <clocale>
#include <cmath>
#include <iomanip>
#define iFILE "input.txt"
#define oFILE "output.txt"
class Point {
public: double x;
public: double y;
};
int main(){setlocale(LC_ALL,"Rus");
std::ifstream inp;inp.open(iFILE);
while(!inp.is_open()){
std::cout << "Файл не найден." << std::endl;
system("pause");
return 0;
}
Point A,B,C;
inp >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
std::ofstream ofs;ofs.open(oFILE);
if( A.y<C.y && A.y>B.y ||
A.y<B.y && A.y>C.y){
double AB = sqrt(pow(C.x-A.x ,2.0)+pow(C.y-A.y ,2.0));
double AC = sqrt(pow(C.x-A.x ,2.0)+pow(C.y-A.y ,2.0));
double CB = sqrt(pow(C.x-B.x ,2.0)+pow(C.y-B.y ,2.0));
double p = (AB+AC+CB)/2;
double S = sqrt(p*(p-AB)*(p-AC)*(p-CB));
double Ah = (2*S)/CB;
ofs << std::fixed << std::setprecision(4) << Ah;
}
else if(A.y==C.y && A.y>B.y || A.y==B.y && A.y>C.y){
double Ah = sqrt(pow(C.x-A.x ,2.0)+pow(C.y-A.y ,2.0));
ofs << std::fixed << std::setprecision(4) << Ah;
}
else
ofs << -1;
ofs.close();
inp.close();
return 0;
}