// BoxT.cc // Pushing Boxes problem // T Feil #include #include using namespace std; int Boxes[20][20]; void initBoxes(int h, int w){ for(int i=0;i>h>>w; while(h>0 && w>0){ cout<<"Data set "<>n; for(int i=0;i>ii>>jj; Boxes[ii][jj]=1; } cin>>direction; while(strcmp(direction,"done")!=0){ cin>>n; if(strcmp(direction,"down")==0){ //1st see how far down int max=0; for(int j=0;jmax) max=count; } if(h-maxmax) max=count; } if(h-max=h-n;i--){ if(Boxes[i][j]){ //found a box to move up Boxes[i][j]=0; k=i-1; while(Boxes[k][j]) k--; Boxes[k][j]=1; } } } } // else if(direction=="left"){ else if(strcmp(direction,"left")==0){ //1st see how farleft int max=0; for(int i=0;imax) max=count; } if(w-max=w-n;j--){ if(Boxes[i][j]){ //found a box to move up Boxes[i][j]=0; k=j-1; while(Boxes[i][k]) k--; Boxes[i][k]=1; } } } } // else if(direction=="right"){ else if(strcmp(direction,"right")==0){ //1st see how far right int max=0; for(int i=0;imax) max=count; } if(w-max>direction; } printBoxes(h,w); cin>>h>>w; } return 0; }