/* Subject: Contest submission for problem #3, file 3.cc */ /* cs188-ah@imail.EECS.Berkeley.EDU */ /* Tue Sep 9 01:12:56 PDT 2003 */ /*___CONTEST_SUBMISSION___ cs188-ah 3 */ //Assignment 2 //Problem 3 //SID 14394533 #include #include using namespace std; class Window; class Window { private: size_t mw, mh; size_t mox, moy; size_t mux, muy; size_t muw, muh; size_t mname; vector sub; public: Window(size_t name) : mname(name) {} Window(size_t ww, size_t hh) : mw(ww), mh(hh), mox(0), moy(0), mux(0), muy(0), muw(ww), muh(hh), mname(1) { } ~Window() {} void add(Window* sw, size_t dim, char side); friend ostream& operator<<(ostream&os, const Window& w); }; ostream& operator<<(ostream&os, const Window& w) { os << w.mname << ". " << w.mw << "x" << w.mh << " @ (" << w.mox << ","<< w.moy << ")"; return os; } void Window::add(Window *sw, size_t dim, char side) { //child dimensions and stuff size_t cw, ch, cox, coy; switch(side) { case 'T': cw = muw; ch = dim; cox = mux; coy = muy + muh - dim; muh = muh - dim; break; case 'B': cw = muw; ch = dim; cox = mux; coy = muy; muh = muh - dim; muy = muy + dim; break; case 'L': cw = dim; ch = muh; cox = mux; coy = muy; mux = mux + dim; muw = muw - dim; break; case 'R': cw = dim; ch = muh; cox = mux + muw - dim; coy = muy; muw = muw - dim; } sw->mw = cw; sw->mh = ch; sw->mox = cox; sw->moy = coy; sw->muh = ch; sw->muw = cw; sw->mux = cox; sw->muy = coy; } int main(int argc, char* argv[]) { vector ws; size_t w1, h1; size_t cnt = 1; size_t name; cin >> w1; cin >> h1; ws.push_back(new Window(w1, h1)); while(cin >> name) { size_t parent, dim; char s; cin >> parent >> dim >> s; ws.push_back(new Window(name)); cnt++; ws[parent-1]->add(ws[name-1], dim, s); } for(vector::iterator vi = ws.begin(); vi != ws.end(); vi++){ cout << *(*vi) << endl; delete *vi; } }