-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpashmakAndGarden.cpp
134 lines (122 loc) · 3.06 KB
/
pashmakAndGarden.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int x1,x2,x3,x4,y1,y2,y3,y4;
cin>>x1>>y1>>x2>>y2;
// implementation :
// CASE 1 :
if(y1==y2){
int l;
if(x2>=x1){
l = x2-x1;
}
else if(x2<x1){
l = x1-x2;
}
int x3 = x1;
int x4 = x2;
int y3 = y1+l;
int y4 = y2+l;
if(-1000<=x3<=1000 && -1000<=x4<=1000 && -1000<=y3<=1000 && -1000<=y4<=1000){
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
return 0;
}
else {
cout<<"-1";
return 0;
}
}
// CASE 2 :
if(x1==x2){
int l;
if(y2>=y1){
l = y2-y1;
}
else if(y2<y1){
l = y1-y2;
}
int y3 = y2;
int y4 = y1;
int x3 = x2+l;
int x4 = x1+l;
if(-1000<=x3<=1000 && -1000<=x4<=1000 && -1000<=y3<=1000 && -1000<=y4<=1000){
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
return 0;
}
else {
cout<<"-1";
return 0;
}
}
// CASE 3 :
float checkerlog1 = float(y2)-float(y1);
float checkerlog2 = float(x2)-float(x1);
float checkerlog = checkerlog1/checkerlog2;
if(checkerlog == 1 ){
float diagonal = sqrt(pow((x2-x1),2)+pow((y2-y1),2));
float side = diagonal/sqrt(2);
int sidelength = int(side);
if(x2>x1){
x3 = x2 - sidelength;
y3 = y2;
x4 = x1 + sidelength;
y4 = y1;
if(-1000<=x3<=1000 && -1000<=x4<=1000 && -1000<=y3<=1000 && -1000<=y4<=1000){
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
return 0;
}
else {
cout<<"-1";
return 0;
}
}
else if(x2<x1){
x3 = x1-sidelength;
y3 = y1;
x4 = x2+sidelength;
y4 = y2;
if(-1000<=x3<=1000 && -1000<=x4<=1000 && -1000<=y3<=1000 && -1000<=y4<=1000){
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
return 0;
}
else {
cout<<"-1";
return 0;
}
}
}
if(checkerlog==-1){
float diagonal = sqrt(pow((x2-x1),2)+pow((y2-y1),2));
float side = diagonal/sqrt(2);
int sidelength = int(side);
if(x1>x2){
x3 = x2;
y3 = y1; x4 = x1; y4 = y2;
if(-1000<=x3<=1000 && -1000<=x4<=1000 && -1000<=y3<=1000 && -1000<=y4<=1000){
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
return 0;
}
else {
cout<<"-1";
return 0;
}
}
else if(x1<x2){
x3 = x1; y3 = y2; x4 = x2; y4 = y1;
if(-1000<=x3<=1000 && -1000<=x4<=1000 && -1000<=y3<=1000 && -1000<=y4<=1000){
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
return 0;
}
else {
cout<<"-1";
return 0;
}
}
}
else {
cout<<"-1";
return 0;
}
}