-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuva-105.cpp
75 lines (56 loc) · 1.19 KB
/
uva-105.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
//uva 105
//The Skyline Problem
#include <iostream>
#include <vector>
using namespace std;
struct building
{
int left;
int height;
int right;
};
int findHeight(vector <building> & b, int coordinate);
int main(void)
{
vector <building> buildings;
int t1 = 0, t2 = 0, t3 = 0;
while (cin >> t1 >> t2 >> t3) {
building tmp = { t1, t2, t3 };
buildings.push_back(tmp);
}
int xs = buildings[0].left;
int current_height = 0;
while (true) {
int h = findHeight(buildings, xs);
if (h !=-1 && h != current_height) {
current_height = h;
cout << xs << ' ' << current_height << ' ';
}
if (h == -1) {
cout << xs << ' ' << '0' << endl;
break;
}
++xs;
}
return 0;
}
int findHeight(vector <building> & b, int coordinate)
{
int height = 0;
bool isMax = 1;
for (auto a : b) {
if (coordinate >= a.left && coordinate < a.right && height < a.height) {
height = a.height;
}
if (coordinate < a.left)
break;
}
for (auto a : b)
if (coordinate < a.left || coordinate < a.right) {
isMax = 0;
break;
}
if (isMax)
height = -1;//case the highest number in the coordinates
return height;
}