#include #include #include #include struct Haus { int links; int rechts; int hoehe; }; int main(int argc, char* argv[]) { std::ifstream ifs; std::vector haeuser; if(argc < 2) { std::cerr << "usage: sky \n"; exit(1); } ifs.open(argv[1]); if(!ifs) { std::cerr << "file " << argv[1] << " not found.\n"; exit(1); } while (ifs) { int links, rechts, hoehe; ifs >> links >> rechts >> hoehe; Haus haus = {links, rechts, hoehe}; haeuser.push_back(haus); } ifs.close(); int n = haeuser.size(); int* xCoord = new int[2*n]; for(int i = 0; i < n; ++i) { xCoord[2*i ] = haeuser[i].links; xCoord[2*i+1] = haeuser[i].rechts; } std::sort(xCoord, xCoord + 2*n); int sky = 0; for(int j = 0; j < 2*n; ++j) { int hoehe = 0, x = xCoord[j]; for(int i = 0; i < n; ++i) { if( x >= haeuser[i].links && x < haeuser[i].rechts ) { hoehe = std::max(hoehe, haeuser[i].hoehe); } } if (sky != hoehe) { std::cout << x << "\t" << sky << "\n" << x << "\t" << hoehe << std::endl; sky = hoehe; } } delete[] xCoord; }