-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.cpp
150 lines (146 loc) · 4 KB
/
rectangle.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <string>
#include<sstream>
#include<vector>
using namespace std;
struct Point{
unsigned long long const x , y;
Point(unsigned long long x, unsigned long long y) :
x(x), y(y) { }
Point minx(Point const & rha) const {
return Point(rha.x < x ? rha.x : x, y);
}
Point miny(Point const & rha) const {
return Point(x, rha.y < y ? rha.y : y);
}
Point maxx(Point const & rha) const {
return Point(rha.x > x ? rha.x : x, y);
}
Point maxy(Point const & rha) const {
return Point(x, rha.y > y ? rha.y : y);
}
void print() const {
std :: cout << '(' << x << ', ' << y << ') ';
}
};
struct Rectangle {
unsigned long long const x, y;
Rectangle() :x(0), y(0) {}
Rectangle(unsigned long long _x, unsigned long long _y ) : x(_x), y(_y) {}
Rectangle(Point const & a) : x(a.x), y(a.y) {}
Rectangle operator+(Rectangle const& rha) const {
unsigned long long maxx = 0;
unsigned long long maxy = 0;
if (rha.x > x) {
maxx = rha.x;
}
else {
maxx = x;
}
if (rha.y > y) {
maxy = rha.y;
}
else {
maxy = y;
}
Rectangle r(maxx, maxy);
return r;
}
Rectangle operator*(Rectangle const& rha) const {
unsigned long long minx = 0;
unsigned long long miny = 0;
if (rha.x < x) {
minx = rha.x;
}
else minx = x;
if (rha.y < y) {
miny = rha.y;
}
else miny = y;
Rectangle r(minx, miny);
return r;
}
void print() const {
std::cout << x << y;
}
};
int main()
{
string expression;
getline(cin, expression);
int l = expression.size();
int count = 0;
char m[20]={0};
vector <int> d(l);
string x = "0";
for (int i = 0; i < l; i++) {
if (expression[i] == '(') {
i++;
while (expression[i] != ',') {
x += expression[i];
i++;
}
d[count] = stoi(x);
x = "0";
count++;
i++;
while (expression[i] != ')') {
x += expression[i];
i++;
}
d[count] = stoi(x);
x = "0";
count++;
i++;
if (expression[i] == '+') {
m[count - 1] = '+';
}
else if (expression[i] == '*') {
m[count - 1] = '*';
}
else {
m[count - 1] = '0';
}
}
}
int h = l;
for (int k = 0; k < h; k++) {
if (m[k] == '*') {
Rectangle t1(d[k - 1], d[k]);
Rectangle t2(d[k + 1], d[k + 2]);
Rectangle t3 = t1.operator*(t2);
d[k + 1] = t3.x;
d[k + 2] = t3.y;
d.erase(d.begin() + k);
d.erase(d.begin() + k - 1);
h = h - 2;
for (int g = 0; g < h; g++) {
m[g] = m[g + 2];
}
for (int g = h+2; g >h ; g--) {
m[g] = '0';
}
}
}
if (h > 2) {
for (int k = 0; k < h; k++) {
if (m[k] == '+') {
Rectangle t1(d[k - 1], d[k]);
Rectangle t2(d[k + 1], d[k + 2]);
Rectangle t3 = t1.operator+(t2);
d[k + 1] = t3.x;
d[k + 2] = t3.y;
d.erase(d.begin() + k);
d.erase(d.begin() + k - 1);
h = h - 2;
for (int g = 0; g < h; g++) {
m[g] = m[g + 2];
}
for (int g = h+2; g > h; g--) {
m[g] = '0';
}
}
}
}
cout << '(' << d[0] << ',' << d[1] << ')';
}