## 10267 - Graphical Editor

Moderator: Board moderators

SePulTribe
New poster
Posts: 28
Joined: Mon Nov 15, 2004 5:00 pm

### 10267 Help!!!

[c]
#include <stdio.h>
#include <string.h>

int M, N;
char image[250][250], t[250][250];

void traverse(int X, int Y, char C)
{
int ii, jj;

for (ii = Y - 1; ii >= 0 && t[X][ii] == t[X][Y]; ii--)
image[X][ii] = C;
for (ii = X + 1, jj = Y - 1; ii < M && jj >= 0 && t[ii][jj] == t[X][Y]; ii++, jj--)
image[ii][jj] = C;
for (ii = X + 1; ii < M && t[ii][Y] == t[X][Y]; ii++)
image[ii][Y] = C;
for (ii = X + 1, jj = Y + 1; ii < M && jj < N && t[ii][jj] == t[X][Y]; ii++, jj++)
image[ii][jj] = C;
for (ii = Y + 1; ii < N && t[X][ii] == t[X][Y]; ii++)
image[X][ii] = C;
for (ii = X - 1, jj = Y + 1; ii >= 0 && jj < N && t[ii][jj] == t[X][Y]; ii--, jj++)
image[ii][jj] = C;
for (ii = X - 1; ii >= 0 && t[ii][Y] == t[X][Y]; ii--)
image[ii][Y] = C;
for (ii = X - 1, jj = Y - 1; ii >= 0 && jj >= 0 && t[ii][jj] == t[X][Y]; ii--, jj--)
image[ii][jj] = C;
}

int main(void)
{
char command, C, name[12], buffer[100];
int X, Y, X1, X2, Y1, Y2, ii, jj, temp;

while (fgets(buffer, 100, stdin))
{
command = buffer[0];
buffer[0] = ' ';
switch (command)
{
case 'I': sscanf(buffer, " %d %d", &M, &N);
case 'C': memset(image, 'O', sizeof(char) * 62500);
break;
case 'L': sscanf(buffer, " %d %d %c", &X, &Y, &C);
image[X - 1][Y - 1] = C;
break;
case 'V': sscanf(buffer, " %d %d %d %c", &X, &Y1, &Y2, &C);
if (Y1 > Y2)
{
temp = Y1;
Y1 = Y2;
Y2 = temp;
}
for (ii = Y1 - 1; ii < Y2; ii++)
image[X - 1][ii] = C;
break;
case 'H': sscanf(buffer, " %d %d %d %c", &X1, &X2, &Y, &C);
if (X1 > X2)
{
temp = X1;
X1 = X2;
X2 = temp;
}
for (ii = X1 - 1; ii < X2; ii++)
image[ii][Y - 1] = C;
break;
case 'K': sscanf(buffer, " %d %d %d %d %c", &X1, &Y1, &X2, &Y2, &C);
if (X1 > X2)
{
temp = X1;
X1 = X2;
X2 = temp;
}
if (Y1 > Y2)
{
temp = Y1;
Y1 = Y2;
Y2 = temp;
}
for (jj = Y1 - 1; jj < Y2; jj++)
for (ii = X1 - 1; ii < X2; ii++)
image[ii][jj] = C;
break;
case 'F': sscanf(buffer, " %d %d %c", &X, &Y, &C);
memcpy(t, image, sizeof(char) * 62500);
for (ii = Y - 1; ii >= 0 && t[X][ii] == t[X][Y]; ii--)
traverse(X, ii, C);
for (ii = X + 1, jj = Y - 1; ii < M && jj >= 0 && t[ii][jj] == t[X][Y]; ii++, jj--)
traverse(ii, jj, C);
for (ii = X + 1; ii < M && t[ii][Y] == t[X][Y]; ii++)
traverse(ii, Y, C);
for (ii = X + 1, jj = Y + 1; ii < M && jj < N && t[ii][jj] == t[X][Y]; ii++, jj++)
traverse(ii, jj, C);
for (ii = Y + 1; ii < N && t[X][ii] == t[X][Y]; ii++)
traverse(X, ii, C);
for (ii = X - 1, jj = Y + 1; ii >= 0 && jj < N && t[ii][jj] == t[X][Y]; ii--, jj++)
traverse(ii, jj, C);
for (ii = X - 1; ii >= 0 && t[ii][Y] == t[X][Y]; ii--)
traverse(ii, Y, C);
for (ii = X - 1, jj = Y - 1; ii >= 0 && jj >= 0 && t[ii][jj] == t[X][Y]; ii--, jj--)
traverse(ii, jj, C);
image[X][Y] = C;
break;
case 'S': sscanf(buffer, " %s", name);
printf("%s\n", name);
for (jj = 0; jj < N; jj++)
for (ii = 0; ii < M; ii++)
if (ii < M - 1)
printf("%c", image[ii][jj]);
else
printf("%c\n", image[ii][jj]);
memset(image, 'O', sizeof(char) * 62500);
break;
case 'X': return 0;
}
}

return 0;
}

[/c]

mullusko
New poster
Posts: 2
Joined: Wed Dec 08, 2004 11:19 pm

### Dirty Tricks

Alexander Denisjuk wrote: Well, there is nothing special in this problem.
These is one very dirty trick in there. White is represented as the uppercase letter O, as in Octopus. Not the numeral zero. They print these problems in books, you know. It's cruel. In my book they printed it in a different font than everything else making it even harder to tell.

"Colors are represented by capital letters," I guess, but whether white is a color and whether that refers only to the input is rather ambiguous.

Alexander Denisjuk
New poster
Posts: 35
Joined: Sat Jan 05, 2002 2:00 am
Contact:

### Re: Dirty Tricks

mullusko wrote:
These is one very dirty trick in there. White is represented as the uppercase letter O, as in Octopus. Not the numeral zero.
Note, please, that the following is written explicitly in the problem:
As the parameters there may be: ... the colour - the Latin capital;...

N|N0
New poster
Posts: 36
Joined: Tue Jan 25, 2005 10:33 pm
Location: Ljubljana, Slovenija
Contact:

### 10267 - Graphical Editor

I just can't find out what's wrong

Code: Select all

``````#include <stdio.h>

const char prazno = 'O';
int slika[1+250+1][1+250+1];
int M, N;

void funcL(int x, int y, char c) {
slika[x][y] = c;
return;
};

void funcC(void) {
int i, j;
for (i=1; i<=M; i++)
for (j=1; j<=N; j++)
slika[i][j] = prazno;
return;
};

void funcI(int m, int n) {
M = m;
N = n;
funcC();
return;
};

void funcH(int x1, int x2, int y, char c) {
int i;
for (i=x1; i<=x2; i++)
slika[i][y] = c;
return;
};

void funcV(int x, int y1, int y2, char c) {
int i;
for (i=y1; i<=y2; i++)
slika[x][i] = c;
return;
};

void funcK(int x1, int y1, int x2, int y2, char c) {
int i, j;
for (i=x1; i<=x2; i++)
for (j=y1; j<=y2; j++)
slika[i][j] = c;
return;
}

void recfill(int x, int y, char c, char region) {
if ((1<=x && x<=M) && (1<=y && y<=N)) {
if (slika[x][y] == region) {
slika[x][y] = c;
recfill(x+1, y, c, region);
recfill(x-1, y, c, region);
recfill(x, y+1, c, region);
recfill(x, y-1, c, region);
}
}
}

void funcF(int x, int y, char c) {
if (slika[x][y] != c)
recfill(x, y, c, slika[x][y]);
return;
}

void funcS() {
int i, j;
for (i=1; i<=N; i++) {
for (j=1; j<=M; j++) {
printf("%c", slika[j][i]);
}
if (i < N) printf("\n");
}
return;
}

int main(void) {
int quit = 0, firstS = 1;
char komanda;
int p1, p2, p3, p4;
char pname[8+1+3], pcolor;
while (!quit) {
/* branje komand */
scanf("%c", &komanda);
switch (komanda) {
case 'I':
scanf(" %d %d\n", &p1, &p2);
funcI(p1, p2);
break;
case 'C':
scanf("\n");
funcC();
break;
case 'L':
scanf(" %d %d %c\n", &p1, &p2, &pcolor);
funcL(p1, p2, pcolor);
break;
case 'V':
scanf(" %d %d %d %c\n", &p1, &p2, &p3, &pcolor);
funcV(p1, p2, p3, pcolor);
break;
case 'H':
scanf(" %d %d %d %c\n", &p1, &p2, &p3, &pcolor);
funcH(p1, p2, p3, pcolor);
break;
case 'K':
scanf(" %d %d %d %d %c\n", &p1, &p2, &p3, &p4, &pcolor);
funcK(p1, p2, p3, p4, pcolor);
break;
case 'F':
scanf(" %d %d %c\n", &p1, &p2, &pcolor);
funcF(p1, p2, pcolor);
break;
case 'S':
scanf(" %s", pname);
if (!firstS) printf("\n");
printf("%s\n", pname);
funcS();
firstS = 0;
scanf("%c", &pcolor);
break;
case 'X':
quit = 1;
break;
default:
do { scanf("%c", &pcolor); } while (pcolor != '\n');
break;
}
}
return(0);
}``````
Any idea? Testcases maybe?

nitin
New poster
Posts: 1
Joined: Fri Apr 15, 2005 8:23 pm

### segmentation fault for 10267-Graphical Editor

(10267-Graphical Editor)

Code: Select all

`````` #define SP(x) cout<<endl<<#x<<" : "<<x
#include <iostream>
//#include <stack>
using namespace std;

struct points {
//int x, y;
unsigned char x, y;
};

int main()
{
int m=0, n=0, x1, y1, x2, y2;
char **image=0, *name=new char[15];
int i, j, flag=0;
long top=-1;
char cmd;
char c;	// c color
points *pts=new points[250*250];
//stack <unsigned char> points;

//image[i][j] -- color ar i-th row, j-th col
image=new char* [250];
for (i=0; i<250; i++) {
image[i]=new char[250];
for (j=0; j<250 ; j++) {
image[i][j]='O';
}
}

do
{

cmd=cin.get();
if (cmd==10) cmd=cin.get();
//SP(cmd[0]);
//SP((int)cmd[0]);
switch (cmd) {
case 'I':
cin>>m>>n;		// m cols, n rows
//if (flag) delete[] image;
//image=new char* [n];
//for (i=0; i<n; i++) {
//	image[i]=new char[m];
//	for (j=0; j<m ; j++) {
//		image[i][j]='O';
//	}
//}
for (i=0; i<n; i++) {
for (j=0; j<m; j++) {
image[i][j]='O';
}
}
flag=1;
break;
case 'C':
for (i=0; i<n; i++) {
for (j=0; j<m; j++) {
image[i][j]='O';
}
}
break;
case 'L':
cin>>x1>>y1>>c;		// x1 col, y1 row
image[y1-1][x1-1]=c;
break;
case 'V':
cin>>x1>>y1>>y2>>c;
for (i=y1-1; i<y2; i++) {
image[i][x1-1]=c;
}
break;
case 'H':
cin>>x1>>x2>>y1>>c;
for (i=x1-1; i<x2; i++) {
image[y1-1][i]=c;
}
break;
case 'K':
cin>>x1>>x2>>y1>>y2>>c;
for (i=y1-1; i<y2; i++) {
for (j=x1-1; j<x2; j++) {
image[i][j]=c;
}
}
break;
case 'S':
cin>>name;
cout<<name;
for (i=0; i<n; i++) {
cout<<"\n";
for (j=0; j<m; j++)
cout<<image[i][j];
}
cout<<"\n";
break;
case 'F':
//int currx, curry;
int cx, cy, col;
cin>>x1>>y1>>c;
x1--; y1--;
col=image[y1][x1];
image[y1][x1]=c;

do {
if (x1!=m-1) {	// right adj
cx=x1+1; cy=y1;
if (image[cy][cx]==col) {
image[cy][cx]=c;
//points.push(cy); points.push(cx);
//SP(top);
pts[++top].x=cx;
pts[top].y=cy;
}
}

if (y1!=0) {	// upper adj
cx=x1; cy=y1-1;
if (image[cy][cx]==col) {
image[cy][cx]=c;
//points.push(cy); points.push(cx);
//SP(top);
pts[++top].x=cx;
pts[top].y=cy;
}
}

if (x1!=0) {	// left adj
cx=x1-1; cy=y1;
if (image[cy][cx]==col) {
image[cy][cx]=c;
//points.push(cy); points.push(cx);
//SP(top);
pts[++top].x=cx;
pts[top].y=cy;
}
}

if (y1!=n-1) {	// lower adj
cx=x1; cy=y1+1;
if (image[cy][cx]==col) {
image[cy][cx]=c;
//points.push(cy); points.push(cx);
//SP(top);
pts[++top].x=cx;
pts[top].y=cy;
}
}

if (top==-1) break;
//SP(top);

x1=pts[top].x;
y1=pts[top--].y;

//if (points.empty()) break;

//x1=points.top();	points.pop();
//y1=points.top();	points.pop();

} while (1);
break;
case 'X':
return 0;
default:
//cout<<"\nDEFAULT CASE!! -- "<<cmd[0]<<"\n";
while (cin.get()!='\n');
//cin.getline (cmd, 10);
}

} while (1);

delete []pts;
delete []name;
delete []image;
return 0;
}
``````

pablo
New poster
Posts: 4
Joined: Tue Nov 09, 2004 2:37 am

### 1 hour later...

well, i spend hours testing, reading carefully the code and going over every tip that was mentioned in the forum, and i keep getting WA, can anyone help me?

Code: Select all

``````#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
using namespace std;
typedef long tint;
#define forn(i,n) if(true)for(tint i=1;i<(n);++i)
#define forsn(i,s,n) if(true)for(tint i=s;i<(n);++i)

vector< vector< char > > ps;

void pix(int x, int y, char c) {
ps[x][y]=c;
}

void rect(int x1, int y1, int x2, int y2, char c) {
forsn(x,x1,x2+1)forsn(y,y1,y2+1)pix(x,y,c);
}

void lh(int x1, int x2, int y, char c) {
if(x1>x2) swap(x1,x2);
rect(x1, y, x2, y, c);
}

void lv(int x, int y1, int y2, char c) {
if(y1>y2) swap(y1,y2);
rect(x, y1, x, y2, c);
}

void ini(int a, int b) {
ps = vector< vector< char > >(a+1, vector<char>(b+1, 'O'));
}

void cl() {
ini(ps.size(), ps[0].size());
}

void sa(string n) {
cout << n << endl;
forn(y,ps[0].size()) {
forn(x,ps.size()) cout << ps[x][y];
cout << endl;
}
}

void fil(int x, int y, char cf, char ct) {
if (x<1 || x >= ps.size() || y < 1 || y >= ps[x].size()) return;
if (ps[x][y]!=cf) return;
ps[x][y]=ct;
fil(x+1,y,cf,ct);
fil(x-1,y,cf,ct);
fil(x,y+1,cf,ct);
fil(x,y-1,cf,ct);
}

void fil(int x, int y, char c) {
if (ps[x][y]!=c) fil(x,y,ps[x][y],c);
}

int main() {
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
string s;
while(true) {
getline(cin, s);
istringstream in(s);
char com;
int a,b,c,d;
char col;
string n;
in >> com;
switch(com) {
case 'X': return 0;
case 'C':
cl();
break;
case 'L':
in >> a >> b >> col;
pix(a,b,col);
break;
case 'F':
in >> a >> b >> col;
fil(a,b,col);
break;
case 'V':
in >> a >> b >> c >> col;
lv(a,b,c,col);
break;
case 'H':
in >> a >> b >> c >> col;
lh(a,b,c,col);
break;
case 'K':
in >> a >> b >> c >> d >> col;
rect(a,b,c,d,col);
break;
case 'S':
in >> n;
sa(n);
break;
case 'I':
in >> a >> b;
ini(a,b);
break;
}
}
return 0;
}
``````
thanks!

Iwashere
New poster
Posts: 20
Joined: Mon Aug 11, 2003 1:50 pm
Location: Singapore

Code: Select all

``````#include <stdio.h>
#include <string.h>

int i, j, m, n, x, x1, x2, y, y1, y2;
char c, com, dummy, name[13], pic[250][250];

void ffill (int x, int y, char c, char o){
if (c==o){
return;
}
if (pic[y][x]==o){
pic[y][x]=c;
if (y!=0){
ffill(x, y-1, c, o);
}
if (x!=0){
ffill(x-1, y, c, o);
}
if (x!=m-1){
ffill(x+1, y, c, o);
}
if (y!=n-1){
ffill(x, y+1, c, o);
}
}
}

int main(){
while(1){
scanf("%c", &com);
if (com=='X'){
break;
}
switch(com){
case 'I':
scanf("%d %d", &m, &n);
case 'C':
memset(pic, 'O', sizeof(pic));
break;
case 'L':
scanf("%d %d %c", &x, &y, &c);
pic[y-1][x-1]=c;
break;
case 'V':
scanf("%d %d %d %c", &x, &y1, &y2, &c);
if (y1>y2){
y1^=y2;
y2^=y1;
y1^=y2;
}
for (i=y1; i<=y2; i++){
pic[i-1][x-1]=c;
}
break;
case 'H':
scanf("%d %d %d %c", &x1, &x2, &y, &c);
if (x1>x2){
x1^=x2;
x2^=x1;
x1^=x2;
}
for (i=x1; i<=x2; i++){
pic[y-1][i-1]=c;
}
break;
case 'K':
scanf("%d %d %d %d %c", &x1, &y1, &x2, &y2, &c);
for (j=y1; j<=y2; j++){
for (i=x1; i<=x2; i++){
pic[j-1][i-1]=c;
}
}
break;
case 'F':
scanf("%d %d %c", &x, &y, &c);
ffill(x, y, c, pic[y-1][x-1]);
break;
case 'S':
scanf("%s", name);
printf("%s\n", name);
for (j=0; j<n; j++){
for (i=0; i<m; i++){
printf("%c", pic[j][i]);
}
printf("\n");
}
break;
case '\n':
break;
default:
while(1){
dummy=getchar();
if (dummy=='\n'){
break;
}
}
}
}
return 0;
}
``````
Thanks!

A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm

### 10267 - Graphical Editor - TLE

I got TLE - any suggestions.
Here is my code:

Code: Select all

``````#include <stdio.h>
#include <stack>
using namespace std;
char image[300][300];
void clear(int,int);
//void dfs(int,int,char,char);
void bfs_flood(int x,int y, char c, char f,int,int);
int main()
{
int i,j,m,n,x,y,x1,y1;
char c,f,fow[500],name[500],C;
//freopen("10267.in","r",stdin);
//freopen("10267.out","w",stdout);
while(scanf("%c",&c)==1 && c!='X')
{
if(c=='I')
{
scanf("%d %d",&m,&n);getchar();
clear(n,m);
}
else if(c=='C')
{
getchar();
clear(n,m);
}
else if(c=='L')
{
scanf("%d %d %c",&x,&y,&C);getchar();
image[y][x]=C;
}
else if(c=='V')
{
scanf("%d %d %d %c",&x,&y,&y1,&C);getchar();
if(y>y1){y^=y1;y1^=y;y^=y1;}
for(i=y;i<=y1;i++)
{
image[i][x]=C;
}
}
else if(c=='H')
{
scanf("%d %d %d %c",&x,&x1,&y,&C);getchar();
if(x>x1){x^=x1;x1^=x;x^=x1;}
for(i=x;i<=x1;i++)
{
image[y][i]=C;
}
}
else if(c=='K')
{
scanf("%d %d %d %d %c",&x,&y,&x1,&y1,&C);getchar();
if(x>x1){x^=x1;x1^=x;x^=x1;}
for(i=x;i<=x1;i++)
{
for(j=y;j<=y1;j++)
{
image[i][j]=C;
}
}
}
else if(c=='F')
{
scanf("%d %d %c",&x,&y,&C);getchar();
f=image[x][y];
bfs_flood(x,y,C,f,n,m);
}
else if(c=='S')
{
scanf("%s",name);getchar();
puts(name);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
printf("%c",image[i][j]);
}
printf("\n");
}

}
else
{
gets(fow);
}
}
return 0;
}

void clear(int n,int m)
{
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
image[i][j]='0';
}
}
}
struct poi{int x, y;};
stack<poi>stk;
void bfs_flood(int x,int y, char c, char f,int n,int m)
{
poi V;
int i,j,a,b,k,l;
image[x][y]=c;
V.x=x;
V.y=y;
stk.push(V);
while(!stk.empty())
{
V=stk.top();
x=V.x;
y=V.y;
a=x-1;		if(a<1)		a=1;
b=y-1;		if(b<1)		b=1;
k=x+1;		if(k>n)		k=n;
l=y+1;		if(l>m)		l=m;

stk.pop();
for(i=a;i<=k;i++)
for(j=b;j<=l;j++)
{
if(image[i][j]==f)
{
image[i][j]=c;
V.x=i;V.y=j;
stk.push(V);
}
}
}

}
/*void dfs(int x,int y,char c,char f)
{
int i,j,a,b,k,l;

a=x-1;
if(a<1)a=1;
b=y-1;
if(b<1)b=1;
k=x+1;
if(k>250)k=250;
l=y+1;
if(l>250)l=250;

for(i=a;i<=k;i++)
for(j=b;j<=l;j++)
{
if(image[i][j]==f)
{
image[i][j]=c;
dfs(i,j,c,f);
}
}
}*/``````

Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

### 10267 - Runtime Error ( --> A Lot Of HEADACHE !!! )

Here is my code:

Code: Select all

``````#include <stdio.h>
#include <string.h>

#define MAX 252

typedef const int cint;
typedef const char cchar;

char map[MAX][MAX];

void createAndClearImage( cint m, cint n )
{
int i = 0, j = 0;

for ( i = 0; i < n; i++ )
{
memset( map[i], '\0', sizeof( map[i] ) );

for ( j = 0; j < m; j++ )
map[i][j] = 'O';
}
}

void colorImage( cint x, cint y, cchar color )
{
map[ y - 1 ][ x - 1 ] = color;
}

void drawVerticalLine( cint x, int y1, int y2, cchar color )
{
if ( y1 > y2 )
y1 ^= y2 ^= y1 ^= y2;

while ( y1 <= y2 )
{
map[ y1 - 1 ][ x - 1 ] = color;
y1++;
}
}

void drawHorizontalLine( int x1, int x2, cint y, cchar color )
{
if ( x1 > x2 )
x1 ^= x2 ^= x1 ^= x2;

while ( x1 <= x2 )
{
map[ y - 1 ][ x1 - 1 ] = color;
x1++;
}
}

void drawFilledRectangle( cint x1, cint y1, cint x2, cint y2, cchar color )
{
int i = 0, j = 0;

for ( i = y1; i <= y2; i++ )
for ( j = x1; j <= x2; j++ )
map[ i - 1 ][ j - 1 ] = color;
}

void floodFill( cint x, cint y, cchar color, cint m, cint n )
{
char temp = map[y][x];

map[y][x] = color;

// north east
if ( y - 1 >= 0 && x + 1 < m && map[y - 1][x + 1] == temp )
floodFill( x + 1, y - 1, color, m, n );

// east
if ( x + 1 < m && map[y][x + 1] == temp )
floodFill( x + 1, y, color, m, n );

// south east
if ( y + 1 < n && x + 1 < m && map[y + 1][x + 1] == temp )
floodFill( x + 1, y + 1, color, m, n );

// south
if ( y + 1 < n && map[y + 1][x] == temp )
floodFill( x, y + 1, color, m, n );

// south west
if ( y + 1 < n && x - 1 >= 0 && map[y + 1][x - 1] == temp )
floodFill( x - 1, y + 1, color, m, n );

// west
if ( x - 1 >= 0 && map[y][x - 1] == temp )
floodFill( x - 1, y, color, m, n );

// north west
if ( y - 1 >= 0 && x - 1 >= 0 && map[y - 1][x - 1] == temp )
floodFill( x - 1, y - 1, color, m, n );

// north
if ( y - 1 >= 0 && map[y - 1][x] == temp )
floodFill( x, y - 1, color, m, n );
}

char * checkDOSNameFormat( char * str )
{
int i = 0, j = 0, k = 0, len = strlen( str );

for ( i = 0; i < len; i++ )
{
if ( str[i] == '.' )
{
k = 1;
str[j++] = '.';
}
else if ( !k && j < 8 )
str[j++] = str[i];
else if ( k && j < 12 )
str[j++] = str[i];
}

return str;
}

void writeImage( char * name, cint m, cint n )
{
int i = 0, j = 0;

printf( "%s\n", name );

for ( i = 0; i < n; i++ )
{
for ( j = 0; j < m; j++ )
printf( "%c", map[i][j] );

printf( "\n" );
}
}

int main()
{
char command = 0, color = 0;
char dummy[MAX] = { 0 };
int m = 0, n = 0, x1 = 0, x2 = 0, y1 = 0, y2 = 0;

while ( scanf( "%c\n", &command ) == 1 )
{
if ( command == 'X' )
break;

switch ( command )
{
case 'I' : // create new image with m x n size
scanf( "%d %d\n", &m, &n );
createAndClearImage( m, n );
break;
case 'C' : // clear image table (filled with 'O')
createAndClearImage( m, n );
break;
case 'L' : // color image with 'color' in coordinate x,y
scanf( "%d %d %c\n", &x1, &y1, &color );
colorImage( x1, y1, color );
break;
case 'V' : // draw vertical line with 'color'
scanf( "%d %d %d %c\n", &x1, &y1, &y2, &color );
drawVerticalLine( x1, y1, y2, color );
break;
case 'H' : // draw horizontal line with 'color'
scanf( "%d %d %d %c\n", &x1, &x2, &y1, &color );
drawHorizontalLine( x1, x2, y1, color );
break;
case 'K' : // draw filled rectangle with 'color' from x1,y1 to x2,y2
scanf( "%d %d %d %d %c\n", &x1, &y1, &x2, &y2, &color );
drawFilledRectangle( x1, y1, x2, y2, color );
break;
case 'F' : // filled region with 'color' start in coordinate x,y
scanf( "%d %d %c\n", &x1, &y1, &color );
floodFill( x1 - 1, y1 - 1, color, m, n );
break;
case 'S' : // write the image with the given name
memset( dummy, '\0', sizeof( dummy ) );
gets( dummy );
strcpy( dummy, checkDOSNameFormat( dummy ) );
writeImage( dummy, m, n );
break;
default : // invalid command
gets( dummy );
break;
}
}

return 0;
}``````

worldguy
New poster
Posts: 4
Joined: Sat May 07, 2005 2:31 pm
Location: China

I used an iterative method to fill rectangles and didn't notice the situations when x>m or y>n. After fixed the little bug, I got AC.

The input seems to be regular, not too tricky, I think. When you are crazy about your countless WA's, just pay attention to the fill part.

sectroyer
New poster
Posts: 8
Joined: Mon Nov 28, 2005 4:55 pm

### Graphical Editor strange WA :(

I keep getting wrong answer on this code.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char pic[261][261];
int c,l,deep;

void chclr(int x,int y,char cl,char cl2)
{
if(((x-1) >= 0) && (pic[x-1][y]==cl))
{
pic[x-1][y]=cl2;
chclr(x-1,y,cl,cl2);
}
if(((x+1) <= 260) && (pic[x+1][y]==cl))
{
pic[x+1][y]=cl2;
chclr(x+1,y,cl,cl2);
}
if(((y-1) >= 0) && (pic[x][y-1]==cl))
{
pic[x][y-1]=cl2;
chclr(x,y-1,cl,cl2);
}
if(((y+1) <= 260) && (pic[x][y+1]==cl))
{
pic[x][y+1]=cl2;
chclr(x,y+1,cl,cl2);
}
}
int main(int argc, char *argv[])
{
char ch,tch;
char name[1000];
int x,x1,x2,y,y1,y2,z,tmp;
while((scanf("%c",&ch) != EOF))
{
if(ch=='X')
break;
if(ch=='I')
{
scanf("%d %d",&c,&l);
memset(pic,'O',sizeof(pic));
}
else if(ch=='L')
{
scanf("%d %d %c",&x,&y,&tch);
pic[x-1][y-1]=tch;
}
else if(ch=='S')
{
scanf("%s",&name);
printf("%s\n",name);
for(y=0;y<l;y++)
{
for(x=0;x<c;x++)
putchar(pic[x][y]);
putchar('\n');
}
tmp=0;
}
else if(ch=='C')
{
memset(pic,'O',sizeof(pic));
}
else if(ch=='V')
{
scanf("%d %d %d %c",&x,&y1,&y2,&tch);
if(y1 > y2)
{
tmp=y2;
y2=y1;
y1=tmp;
}
for(y=y1;y<=y2;y++)
pic[x-1][y-1]=tch;
}
else if(ch=='H')
{
scanf("%d %d %d %c",&x1,&x2,&y,&tch);
if(x1 > x2)
{
tmp=x2;
x2=x1;
x1=tmp;
}
for(x=x1;x<=x2;x++)
pic[x-1][y-1]=tch;
}
else if(ch=='K')
{
scanf("%d %d %d %d %c",&x1,&y1,&x2,&y2,&tch);
if(x1 > x2)
{
tmp=x2;
x2=x1;
x1=tmp;
}
if(y1 > y2)
{
tmp=y2;
y2=y1;
y1=tmp;

}
for(y=y1;y<=y2;y++)
{
for(x=x1;x<=x2;x++)
pic[x-1][y-1]=tch;
}
}
else if(ch=='F')
{
scanf("%d %d %c",&x,&y,&tch);
deep=0;
if(tch!=pic[x-1][y-1])
chclr(x-1,y-1,pic[x-1][y-1],tch);
}
/*
else
{
gets(name);
continue;
}
getchar();
*/
gets(name);

}
return 0;
}

ibroker
New poster
Posts: 18
Joined: Tue Nov 08, 2005 6:38 pm

### 10267 plz help me

I want to solve this problem.!
I know how to solve this problem. but I don't know why I got WA
plz help me..

#include <string.h>
#include <stdio.h>
#include <conio.h>

#define M 260

int m, n;
char start;
int x, x2, y, y2;
char c;
char data[M][M];
char name[20];

void fills(int, int, int, int, char);
void bfs(int, int, char);

int main()
{
char temp[30];

while(scanf("%c", &start)==1)
{
if(start=='I')
{
scanf("%d %d", &m, &n);
fflush(stdin);
fills(1, m, 1, n, 'O');
}
else if(start=='C') fills(1, m, 1, n, 'O');
else if(start=='L')
{
scanf("%d %d %c", &x, &y, &c);
fflush(stdin);
fills(x, x, y, y, c);
}
else if(start=='V')
{
scanf("%d %d %d %c", &x, &y, &y2, &c);
fflush(stdin);
fills(x, x, y, y2, c);
fills(x, x, y2, y, c);
}
else if(start=='H')
{
scanf("%d %d %d %c", &x, &x2, &y, &c);
fflush(stdin);
fills(x, x2, y, y, c);
fills(x2, x, y, y, c);
}
else if(start=='K')
{
scanf("%d %d %d %d %c", &x, &y, &x2, &y2, &c);
fflush(stdin);
fills(x, x2, y, y2, c);
}
else if(start=='F')
{
scanf("%d %d %c", &x, &y, &c);
fflush(stdin);
bfs(x, y, data[y][x]);
}
else if(start=='S')
{
scanf("%s", &name);
fflush(stdin);
printf("%s\n", name);
int i, j;
for(i=1; i<=n; i++){ for(j=1; j<=m; j++) printf("%c", data[j]); printf("\n"); }
}
else if(start=='X'){ name[0]=0; m=n=0; }
else gets(temp);
}

return 0;
}

void bfs(int xx1, int yy1, char C)
{
bool check[M][M];
int quei[M*M], quej[M*M];
int p, q;
int i, j;

for(i=1; i<=n; i++){ for(j=1; j<=m; j++) check[j]=0; }
p=q=0;
check[yy1][xx1]=1;
while(1)
{
data[yy1][xx1]=c;
if(data[yy1+1][xx1]==C && yy1+1<=n)
{
if(!check[yy1+1][xx1])
{
check[yy1+1][xx1]=1;
quei[p]=yy1+1, quej[p++]=xx1;
}
}
if(data[yy1][xx1+1]==C && xx1+1<=m)
{
if(!check[yy1][xx1+1])
{
check[yy1][xx1+1]=1;
quei[p]=yy1, quej[p++]=xx1+1;
}
}
if(data[yy1-1][xx1]==C && yy1-1>0)
{
if(!check[yy1-1][xx1])
{
check[yy1-1][xx1]=1;
quei[p]=yy1-1, quej[p++]=xx1;
}
}
if(data[yy1][xx1-1]==C && xx1-1>0)
{
if(!check[yy1][xx1-1])
{
check[yy1][xx1-1]=1;
quei[p]=yy1, quej[p++]=xx1-1;
}
}
if(q>=p) break;
yy1=quei[q], xx1=quej[q++];
}
return;
}

void fills(int xx1, int xx2, int yy1, int yy2, char C)
{
int i, j;

for(i=yy1; i<=yy2; i++)
{
for(j=xx1; j<=xx2; j++)
{
data[j]=C;
}
}
}

Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:
My first and the only suggestion for you is (if you use C++), use STL to escape from Memory Limit Exceeded or Wrong Answer.

My first approach using BFS data structure for floodfilling the area of the bitmap failed. It gave me Memory Limit Exceeded. If use DFS, It gave me Wrong Answer or Runtime Error. But after I use BFS with STL, it gave me AC (thanx to Johan's help).

Any other idea from other members?

tOd
New poster
Posts: 4
Joined: Thu Dec 29, 2005 5:41 am

### 10267 graphical editor -solved

i don't find wrong result in my program
but i got W.A
plz give me some examples.
Last edited by tOd on Fri Dec 30, 2005 5:11 pm, edited 1 time in total.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am