Tuesday, December 11, 2007

Nested Squares

This is my only ACCEPTED submission during the Dhaka regionals !!!  
____________________________________________________________________
Question: Nested Squares
____________________________________________________________________

#include "iostream.h"

int main()
{
int ns;
cin >> ns;
for(int i = 1; i <= ns; i++) {
cout << "Square " << i << ":" << endl;
char strin[50002];
int nq;
cin >> strin >> nq;
int len = strlen(strin);
int doublen = 2 * len;

for(int j = 1; j <= nq; j++) {
cout << "Query " << j << ":" << endl;
int sx, sy, bx, by;
cin >> sx >> sy >> bx >> by;

for(int k = sx; k <= bx; k++) {
for(int l = sy; l <= by; l++) {
int x = k, y = l;
if(k > len) x = doublen - k;
if(l > len) y = doublen - l;
int min = (x < y)?x:y;
cout << strin[min-1];
}
cout << endl;
}
}
cout << endl;
}
return 0;
}
____________________________________________________________________

No comments:

Contributors