/* Subject: Contest submission for problem #3, file 3.c */ /* cs169-ta@imail.EECS.Berkeley.EDU */ /* Sun Sep 7 19:47:35 PDT 2003 */ /*___CONTEST_SUBMISSION___ cs169-ta 3 */ #include "contest.h" struct window{ int x; int y; int height; int width; int current_x; int current_y; int current_height; int current_width; }; struct window newWin(int x, int y, int height, int width, char side, int parent, struct window win[]){ int temp_x, temp_y, temp_height, temp_width; struct window temp; temp.x=x; temp.y=y; temp.height=height; temp.width=width; temp.current_x=x; temp.current_y=y; temp.current_height=height; temp.current_width=width; if(parent!=-1){ temp_x=win[parent].current_x; temp_y=win[parent].current_y; temp_height=win[parent].current_height; temp_width=win[parent].current_width; switch(side){ case 'T': temp_height=win[parent].current_height-height; break; case 'B': temp_height=win[parent].current_height-height; temp_y=y+height; break; case 'L': temp_width=win[parent].current_width-width; temp_x=x+width; break; case 'R': temp_width=win[parent].current_width-width; break; default: break; } win[parent].current_x=temp_x; win[parent].current_y=temp_y; win[parent].current_height=temp_height; win[parent].current_width=temp_width; } return temp; } main(){ char line[100]; int width, height, self, parent, mag, x, y; x=0; y=0; char side; struct window windows[100]; gets(line); sscanf(line, "%i %i", &width, &height); windows[1]=newWin(0,0,height,width, 'T', -1, windows); printf("1. %ix%i @ (%i,%i)\n", width, height, 0, 0); //printf("%i %i %i %i\n", windows[1].current_x, windows[1].current_y, windows[1].current_height, windows[1].current_width); // x and y in this case are the lower left point while(gets(line)){ sscanf(line, "%i %i %i %c", &self, &parent, &mag, &side); // printf("self %i, parent %i, width %i, side %c", self, parent, width, side); switch(side){ case 'T': x=windows[parent].current_x; y=(windows[parent].current_height+windows[parent].current_y)-mag; width=windows[parent].current_width; height=mag; break; case 'B': x=windows[parent].current_x; y=windows[parent].current_y; width=windows[parent].current_width; height=mag; break; case 'L': x=windows[parent].current_x; y=windows[parent].current_y; width=mag; height=windows[parent].current_height; break; case 'R': x=(windows[parent].current_width+windows[parent].current_x) - mag; y=windows[parent].current_y; width=mag; height=windows[parent].current_height; break; default: break; } windows[self]=newWin(x,y,height,width, side, parent, windows); printf("%i. %ix%i @ (%i,%i)\n", self, width, height, x, y); // printf("%i %i %i %i %i\n", self, windows[self].current_x, windows[self].current_y, windows[self].current_height, windows[self].current_width); //printf("%i %i %i %i %i\n", parent, windows[parent].current_x, windows[parent].current_y, windows[parent].current_height, windows[parent].current_width); } printf("\n"); exit(0); }