10267 - Graphical Editor

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

MewCatcher
New poster
Posts: 19
Joined: Tue Oct 30, 2012 8:19 am

Re: 10267 - WA! Previous topics's test data can output corre

Post by MewCatcher » Sat Nov 03, 2012 3:55 am

:D
You've got a point again.
Let me have a close check!~
Thank you very much!~

MewCatcher
New poster
Posts: 19
Joined: Tue Oct 30, 2012 8:19 am

Re: 10267 - WA! Previous topics's test data can output corre

Post by MewCatcher » Thu Nov 22, 2012 9:21 am

brianfry713 wrote:Input:

Code: Select all

I 2 2
F 2 2 X
S one.bmp
X
Correct output:

Code: Select all

one.bmp
XX
XX
I rewrite "_F" function,
but now it's RE

Please help me!~ :(
Thank you !~

Code: Select all

/*
  Name: 10267 - Graphical Editor
  Copyright: MewCatcher
  Author: MewCatcher
  Date: 01-11-12 16:32
  ReDo: 22/11/12 12:25
  Description: 
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

/*Sample Input
I 5 6
K 1 5 2 1 X
S five.jpeg
K 2 2 5 5 Z
S six.jpeg
C
V 2 3 6 W
S seven.jpeg
C
V 2 6 3 W
S eight.jpeg
C
H 3 5 2 Z
S nine.jpeg
C
H 5 3 2 Z
S ten.jpeg
K 3 3 1 1 K
S eleven.jpeg
X

Sample Output
five.jpeg
XXOOO
XXOOO
XXOOO
XXOOO
XXOOO
OOOOO
six.jpeg
XXOOO
XZZZZ
XZZZZ
XZZZZ
XZZZZ
OOOOO
seven.jpeg
OOOOO
OOOOO
OWOOO
OWOOO
OWOOO
OWOOO
eight.jpeg
OOOOO
OOOOO
OWOOO
OWOOO
OWOOO
OWOOO
nine.jpeg
OOOOO
OOZZZ
OOOOO
OOOOO
OOOOO
OOOOO
ten.jpeg
OOOOO
OOZZZ
OOOOO
OOOOO
OOOOO
OOOOO
eleven.jpeg
KKKOO
KKKZZ
KKKOO
OOOOO
OOOOO
OOOOO
*/

char Order;
char P[ 250 ][ 250 ];
int X, Y;

void _I( int _M, int _N )
{
    memset( P, 'O', sizeof( P ) );
    X = _M;
    Y = _N;
    return;
}

void _C( )
{
    memset( P, 'O' , sizeof( P ) );
    return;
}

void _L( int _X, int _Y, char Color )
{
    P[ _Y - 1 ][ _X - 1 ] = Color;
    return;
}

void _V( int _X, int _Y1, int _Y2, char Color )
{
    int temp;
    if( _Y1 > _Y2 ) {
        temp = _Y1;
        _Y1 = _Y2;
        _Y2 = temp;
    }
    int i;
    _X --;
    for( i = _Y1 - 1; i < _Y2; i ++ ) P[ i ][ _X ] = Color;
    return;
}

void _H( int _X1, int _X2, int _Y, char Color )
{
    int temp;
    if( _X1 > _X2 ) {
        temp = _X1;
        _X1 = _X2;
        _X2 = temp;
    }
    int i;
    _Y --;
    for( i = _X1 - 1; i < _X2; i ++ ) P[ _Y ][ i ] = Color;
    return;
}

void _K( int _X1, int _Y1, int _X2, int _Y2, char Color )
{
    int temp;
    if( _Y1 > _Y2 ) {
        temp = _Y1;
        _Y1 = _Y2;
        _Y2 = temp;
    }
    if( _X1 > _X2 ) {
        temp = _X1;
        _X1 = _X2;
        _X2 = temp;
    }
    int i, j;
    for( j = _Y1 - 1; j < _Y2; j ++ ) {
        for( i = _X1 - 1; i < _X2; i ++ ) {
            P[ j ][ i ] = Color;
        }
    }
    return;
}

void _F_Helper( int _X, int _Y, char DefaultColor, char AimColor )
{
    /*XX( 00, 01 )
    LU( y1, x1 )  RU( y1, x2 )
    LD( y2, x1 )  RD( y2, x2 )
    
    |-0 1 2 3 4 5 x
    0     A 
    1    B?C
    2     D
    3
    4
    5
    y
    */
    if( P[ _Y ][ _X ] == DefaultColor ) P[ _Y ][ _X ] = AimColor;//Here _Y, _X don't need minus 1
    else return;
    
    if( _X - 1 >= 0 ) _F_Helper( _X - 1, _Y, DefaultColor, AimColor );
    if( _X + 1 < X ) _F_Helper( _X + 1, _Y, DefaultColor, AimColor );
    if( _Y - 1 >= 0 ) _F_Helper( _X, _Y - 1, DefaultColor, AimColor );
    if( _Y + 1 < Y ) _F_Helper( _X, _Y + 1, DefaultColor, AimColor );
    return;
}
/*
I 6 6
V 2 1 5 X
V 4 2 6 X
V 6 1 5 X
F 6 6 J
S 123

123
JXJJJX
JXJXJX
JXJXJX
JXJXJX
JXJXJX
JJJXJJ
*/
void _F( int _X, int _Y, char Color )
{
    _F_Helper( _X - 1, _Y - 1, P[ _Y - 1 ][ _X - 1 ], Color );
    return;
}

void _S( char *N )
{
    int i, j;
    printf( "%s\n", N );
    for( i = 0; i < Y; i ++ ) {
        for( j = 0; j < X; j ++ ) {
            printf( "%c", P[ i ][ j ] );
        }
        printf( "\n" );
    }
    return;
}

int main( )
{
    char COM[ 2 ];
    int INT[ 5 ];
    char Name[ 100 ];
    while( scanf( "%c", &Order ), Order != 'X' ) {
        if( Order == 'I' ) {
            scanf( "%d%d", &INT[ 0 ], &INT[ 1 ] );
            _I( INT[ 0 ], INT[ 1 ] );
        }
        else if( Order == 'C' ) {
            _C( );
        }
        else if( Order == 'L' ) {
            scanf( "%d%d%s", &INT[ 0 ], &INT[ 1 ], COM );
            _L( INT[ 0 ], INT[ 1 ], COM[ 0 ] );
        }
        else if( Order == 'V' ) {
            scanf( "%d%d%d%s", &INT[ 0 ], &INT[ 1 ], &INT[ 2 ], COM );
            _V( INT[ 0 ], INT[ 1 ], INT[ 2 ], COM[ 0 ] );
        }
        else if( Order == 'H' ) {
            scanf( "%d%d%d%s", &INT[ 0 ], &INT[ 1 ], &INT[ 2 ], COM );
            _H( INT[ 0 ], INT[ 1 ], INT[ 2 ], COM[ 0 ] );
        }
        else if( Order == 'K' ) {
            scanf( "%d%d%d%d%s", &INT[ 0 ], &INT[ 1 ], &INT[ 2 ], &INT[ 3 ], COM );
            _K( INT[ 0 ], INT[ 1 ], INT[ 2 ], INT[ 3 ], COM[ 0 ] );
        }
        else if( Order == 'F' ) {
            scanf( "%d%d%s", &INT[ 0 ], &INT[ 1 ], COM );
            _F( INT[ 0 ], INT[ 1 ], COM[ 0 ] );
        }
        else if( Order == 'S' ) {
            scanf( "%s", Name );
            _S( Name );
        }
        else if( Order != '\n' ) {
            gets( Name );/*As an empty line*/
        }
        else { }
    }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10267 - WA! Previous topics's test data can output corre

Post by brianfry713 » Fri Nov 30, 2012 6:56 am

Try input:
I 5 5
F 1 1 O
S one.bmp
X
Check input and AC output for thousands of problems on uDebug!

adityaarun1
New poster
Posts: 3
Joined: Mon Jan 21, 2013 4:22 pm

10267 - Graphical Editor: WA

Post by adityaarun1 » Mon Jan 21, 2013 4:38 pm

I have been trying this problem and it works correctly for test input set given in question. Can anyone please point me out where I am going wrong. Thanks.. :)

Code: Select all

#include<stdio.h>

#define MAX 250

void funcF(int, int, char, char);

char disp[MAX][MAX];
int M,N;	/*M->rows N->coloumns*/

int main()
{
	char cmd[5],C,name[1000];
	int X,Y,X1,X2,Y1,Y2;
	int i,j;
	while(1)
	{
		scanf("%s",cmd);
		if(cmd[0]=='X')
			return 0;
		else if(cmd[0]=='I')
		{
			scanf("%d %d",&M,&N);
			for(i=0;i<N;i++)
			{
				for(j=0;j<M;j++)
					disp[i][j]='0';
			}
		}
		else if(cmd[0]=='C')
		{
			for(i=0;i<N;i++)
			{
				for(j=0;j<M;j++)
					disp[i][j]='0';
			}
		}
		else if(cmd[0]=='L')
		{
			scanf("%d %d %c",&X,&Y,&C);
			disp[Y-1][X-1]=C;
		}
		else if(cmd[0]=='F')
		{
			scanf("%d %d %c",&X,&Y,&C);
			char tmp=disp[Y-1][X-1];
			funcF(X,Y,C,tmp);
			/*if(tmp==C)
				continue;
			for(i=0;i<N;i++)
			{
				for(j=0;j<M;j++)
				{
					if(disp[i][j]==tmp)
						disp[i][j]=C;
				}
			}*/
		}
		else if(cmd[0]=='V')
		{
			scanf("%d %d %d %c",&X,&Y1,&Y2,&C);
			if(Y1>Y2)
			{
				int tmp=Y1;
				Y1=Y2;
				Y2=tmp;
			}
			for(i=(Y1-1);i<Y2;i++)
				disp[i][X-1]=C;
		}
		else if(cmd[0]=='H')
		{
			scanf("%d %d %d %c",&X1,&X2,&Y,&C);
			if(X1>X2)
			{
				int tmp=X1;
				X1=X2;
				X2=tmp;
			}
			for(i=(X1-1);i<X2;i++)
				disp[Y-1][i]=C;
		}
		else if(cmd[0]=='K')
		{
			scanf("%d %d %d %d %c",&X1,&Y1,&X2,&Y2,&C);
			if(Y1>Y2)
			{
				int tmp=Y1;
				Y1=Y2;
				Y2=tmp;
			}
			if(X1>X2)
			{
				int tmp=X1;
				X1=X2;
				X2=tmp;
			}
			for(i=(Y1-1);i<Y2;i++)
			{
				for(j=(X1-1);j<X2;j++)
					disp[i][j]=C;
			}
		}
		else if(cmd[0]=='S')
		{
			scanf("%s",name);
			printf("%s\n",name);
			for(i=0;i<N;i++)
			{
				for(j=0;j<M;j++)
					printf("%c",disp[i][j]);
				printf("\n");
			}
		}
		else
		{
			char garbage[1000];
			gets(garbage);
		}
	}
	return 0;
}

void funcF(int X, int Y, char C, char old_C)
{
	if(X<0 || X>M || Y<0 || Y>N || disp[Y-1][X-1]!=old_C || C==old_C)
		return;
	
	disp[Y-1][X-1]=C;
	
	funcF(X,Y-1,C,old_C);	/*up*/
	funcF(X,Y+1,C,old_C);	/*down*/
	funcF(X-1,Y,C,old_C);	/*left*/
	funcF(X+1,Y,C,old_C);	/*right*/
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10267 - Graphical Editor

Post by brianfry713 » Mon Jan 21, 2013 11:32 pm

white is the letter O not the number zero.
Check input and AC output for thousands of problems on uDebug!

Fedaykin
New poster
Posts: 6
Joined: Sun Dec 09, 2012 9:27 pm

Re: 10267 - Graphical Editor

Post by Fedaykin » Tue Jan 29, 2013 2:09 am

7 WA before AC :oops: . The very last thing I fixed was I had assumed incorrectly that 'X' would be the last input, ie if 'X' was inputted there wouldn't be anything after it, but that was wrong. hope that helps someone

jhuliagraziella
New poster
Posts: 4
Joined: Mon Jun 10, 2013 10:04 pm

Re: 10267 - Graphical Editor

Post by jhuliagraziella » Mon Jun 10, 2013 10:13 pm

HELP! D:

I've already gotten 4 Runtime Error's, then 7 WA, and I have no idea of what to do!
I read all the posts about this problem, and my code works fine for all the inputs I tried. If anyone could send me some critical input/output that would sure help a lot!
Here's my code: (I know it's kinda disorganized, it's because I'm still a begginer programmer :T)

Code: Select all

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

char quadro[500][500], atual, cor;
int M=0, N=0;


void infectar(int i, int j)
{
	
	if ((i < 0)||(i >= M)||(j < 0)||(j >= N)||(quadro[i][j] != atual)||(atual == cor))
		return;


		quadro[i][j]=cor;
	
		infectar(i+1,j);
		infectar(i-1,j);
		infectar(i,j+1);	
		infectar(i,j-1);	

}


main()
{
	char comando, nome, lixo;
	int i, j, X, X1, X2, Y, Y1, Y2, aux, k, q, valor;
	

	while((comando=getchar()) != EOF)
	{
		if(comando=='X')
		 break;
		 
		switch(comando)
		{
			case 'I':		//I M N		-> inicia um novo quadro M x N;
				scanf("%d %d\n", &N, &M);
				
				for(i=0;i<M;i++)
				{
					for(j=0;j<N;j++)
						quadro[i][j]='O';
				}
				
				break;


			case 'C':		//C			-> limpa o quadro mudando tudo pra branco (O);
				for(i=0;i<M;i++)
				{
					for(j=0;j<N;j++)
						quadro[i][j]='O';
				}
				break;

			case 'L':		//L X Y C	-> colore o o pixel (X,Y) da cor (C);
				scanf("%d %d %c\n", &X, &Y, &cor);
				
				quadro[Y-1][X-1]=cor;
				break;
				
			case 'V':		//V X Y1 Y2 C	-> desenha uma linha vertical de (X,Y1) a (X,Y2) de cor (C);
				scanf("%d %d %d %c\n", &X, &Y1, &Y2, &cor);

				j=X-1;
								
				if(Y1>Y2) //quero que Y1 seja MENOR;
				 {
				  aux=Y1;
				  Y1=Y2;
				  Y2=aux;
				 }
				
				for(i=Y1-1; i<Y2;i++)
				  quadro[i][j]=cor;
				
				break;
			
			case 'H':		//H X1 X2 Y C	-> desenha uma linha horizontal de (X1,Y) a (X2,Y) de cor (C);
				scanf("%d %d %d %c\n", &X1, &X2, &Y, &cor);

				i=Y-1;				
				
				if(X1>X2) //quero que X1 seja MENOR;
				 {
				  aux=X1;
				  X1=X2;
				  X2=aux;
				 }
			

				for(j=X1-1; j<X2;j++)
				  quadro[i][j]=cor;
				
				break;


			case 'K':		//K X1 Y1 X2 Y2 C-> desenha um retangulo de extremos diagonais (X1,Y1) e (X2,Y2);
				scanf("%d %d %d %d %c\n", &X1, &Y1, &X2, &Y2, &cor);

				
				for(i=Y1-1;i<Y2;i++)
				{
					for(j=X1-1;j<X2;j++)
						{quadro[i][j]=cor;}
				}
				
				break;
			
			
			
			
			
			case 'F':		//F X Y C -> preenche a regiao R: o pixel (X,Y) e todos os q tenham a mesma cor q ele e sejam adjacentes a ele sao da regiao R;
				scanf("%d %d %c\n", &X, &Y, &cor);
			
				atual=quadro[Y-1][X-1];
				infectar(Y-1, X-1);

				
				
			
				break;
			
			
			
			case 'S':		//S name		-> escrever o nome e printar a imagem;

			getchar(); //pra pegar o espaço
				while((nome=getchar()) != '\n')
					printf("%c", nome);
				
				printf("\n");
				
				for(i=0;i<M;i++)
				{
					for(j=0;j<N;j++)
						printf("%c", quadro[i][j]);
					printf("\n");
				}
			
				break;
				
			default:
				lixo=getchar();
				while(lixo != '\n')
				 {if(lixo == EOF)  break;
				  lixo=getchar();}
				 
				break;
		}
	}
}


 

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10267 - Graphical Editor

Post by brianfry713 » Wed Jun 12, 2013 12:47 am

Input:

Code: Select all

I 6 7
L 3 3 A
C
H 5 1 5 Z
S o.bmp
S k.bmp
H 6 4 6 K
S u.bmp
S t.bmp
V 2 1 7 H
I 4 4
L 2 3 Z
I 9 5
V 2 4 1 U
V 4 5 4 X
F 4 1 Y
V 4 1 1 W
F 9 5 F
V 8 3 3 F
F 2 3 V
I 3 3
F 3 3 V
V 2 2 1 K
C
V 1 3 1 I
V 2 2 3 T
S p.bmp
V 2 1 3 X
F 2 3 S
K 3 3 2 2 I
F 2 3 U
V 3 3 2 E
I 1 1
C
H 1 1 1 P
K 1 1 1 1 R
S h.bmp
C
S p.bmp
L 1 1 A
L 1 1 J
L 1 1 X
S k.bmp
V 1 1 1 V
F 1 1 L
K 1 1 1 1 R
H 1 1 1 Q
S y.bmp
S f.bmp
F 1 1 T
V 1 1 1 J
I 6 9
F 4 5 K
L 1 2 R
C
C
L 1 7 J
S g.bmp
H 5 1 6 J
S z.bmp
H 5 4 2 Y
F 4 3 Y
L 1 5 Y
K 6 2 5 9 M
H 6 4 5 D
H 2 2 6 U
H 5 2 1 O
L 1 8 R
H 2 3 3 H
S f.bmp
I 1 4
C
S j.bmp
I 6 4
H 4 2 2 E
H 3 2 4 H
C
K 2 1 4 2 M
I 1 1
S b.bmp
F 1 1 D
I 5 3
I 10 1
H 2 6 1 M
V 2 1 1 G
F 4 1 P
K 5 1 6 1 D
F 8 1 W
H 9 4 1 G
L 3 1 J
S d.bmp
S s.bmp
K 10 1 7 1 C
H 10 5 1 L
I 5 4
F 2 4 S
V 5 1 1 B
F 5 4 T
I 3 5
L 1 3 F
V 2 2 1 Q
X
AC output:

Code: Select all

o.bmp
OOOOOO
OOOOOO
OOOOOO
OOOOOO
ZZZZZO
OOOOOO
OOOOOO
k.bmp
OOOOOO
OOOOOO
OOOOOO
OOOOOO
ZZZZZO
OOOOOO
OOOOOO
u.bmp
OOOOOO
OOOOOO
OOOOOO
OOOOOO
ZZZZZO
OOOKKK
OOOOOO
t.bmp
OOOOOO
OOOOOO
OOOOOO
OOOOOO
ZZZZZO
OOOKKK
OOOOOO
p.bmp
IOO
ITO
ITO
h.bmp
R
p.bmp
O
k.bmp
X
y.bmp
Q
f.bmp
Q
g.bmp
OOOOOO
OOOOOO
OOOOOO
OOOOOO
OOOOOO
OOOOOO
JOOOOO
OOOOOO
OOOOOO
z.bmp
OOOOOO
OOOOOO
OOOOOO
OOOOOO
OOOOOO
JJJJJO
JOOOOO
OOOOOO
OOOOOO
f.bmp
YOOOOY
YYYYMM
YHHYMM
YYYYMM
YYYDDD
JUJJMM
JYYYMM
RYYYMM
YYYYMM
j.bmp
O
O
O
O
b.bmp
O
d.bmp
OGJGGGGGGW
s.bmp
OGJGGGGGGW
Check input and AC output for thousands of problems on uDebug!

jhuliagraziella
New poster
Posts: 4
Joined: Mon Jun 10, 2013 10:04 pm

Re: 10267 - Graphical Editor

Post by jhuliagraziella » Wed Jun 19, 2013 1:03 am

Bryanfry, THANK YOU SO MUCH!!!!!!

It was just a little mistake, I wasn't checking if X1 < X2 and Y1 < Y2 in K function, and my code was getting garbage after the C function...
Finally AC, I'm really happy, you helped a lot, ty! :D

aybek
New poster
Posts: 19
Joined: Fri Jul 19, 2013 10:25 am
Contact:

Find critical input

Post by aybek » Tue Jul 23, 2013 7:16 am

Problem graphical editor
http://uva.onlinejudge.org/index.php?op ... oblem=1208
always get WA. think that I don't consider some critical input.
Please, Help to find it. :wink:
The code is below:

Code: Select all

#include <stdio.h>
#include <ctype.h>

#define MAXX 252
#define MAXY 252

#define CREATE_IMAGE	'I'
#define CLEAR_IMAGE		'C'
#define DRAW_PIXEL		'L'
#define DRAW_VLINE		'V'
#define DRAW_HLINE		'H'
#define DRAW_FREC		'K'
#define FILL			'F'
#define SAVE_IMAGE		'S'
#define CLOSE_PROG		'X'


struct image {
	int M, N;
	char title[20];
	char pic[MAXX][MAXY];
};

struct image file;

void create_image(void);
void save_image(void);
void clear_image(void);
void draw_pixel(int, int, char);
void draw_hline(int, int, int, char);
void draw_vline(int, int, int, char);
void draw_frec(int, int, int, int, char);
void fill(int, int, char);

int main()
{
	char command;
	char c; int x, y, x1, x2, y1, y2;

	for (x = 0; x < MAXX; x++)
		for (y = 0; y < MAXY; y++)
			file.pic[x][y] = 0;

	while (1) {
		scanf("%c ", &command);

		if (command == CLOSE_PROG)
			break;

		switch (command) {
			case CREATE_IMAGE :
				scanf("%d %d\n", &file.M, &file.N);
				create_image();
				break;

			case CLEAR_IMAGE :
				clear_image();
				break;
			case DRAW_PIXEL :
				scanf("%d %d %c\n", &x, &y, &c);
				draw_pixel(x, y, c);
				break;
			case DRAW_VLINE :
				scanf("%d %d %d %c\n", &x, &y1, &y2, &c);
				draw_vline(x, y1, y2, c);
				break;
			case DRAW_HLINE :
				scanf("%d %d %d %c\n", &x1, &x2, &y, &c);
				draw_hline(x1, x2, y, c);
				break;
			case DRAW_FREC :
				scanf("%d %d %d %d %c\n", &x1, &x2, &y1, &y2, &c);
				draw_frec(x1, x2, y1, y2, c);
				break;
			case FILL :
				scanf("%d %d %c\n", &x, &y, &c);
				fill(x, y, c);
				break;

			case SAVE_IMAGE :
				scanf("%s\n", (file.title));
				save_image();
				break;
			default :
				break;
		}
	}

	return 0;
}

void create_image(void)
{
	int i, j;

	for (i = 1; i <= file.M; i++)
		for (j = 1; j <= file.N; j++)
			file.pic[i][j] = 'O';
}
void save_image(void)
{
	int i, j;

	printf("%s\n", file.title);
	for (i = 1; i <= file.M; i++) {
		for (j = 1; j <= file.N; j++)
			printf("%c", file.pic[j][i]);
		printf("\n");
	}
}
void clear_image(void)
{
	int i, j;
	for (i = 1; i <= file.M; i++)
		for (j = 1; j <= file.N; j++)
			file.pic[i][j] = 'O';
}
void draw_pixel(int x, int y, char c)
{
	file.pic[x][y] = c;
}
void draw_hline(int x1, int x2, int y, char c)
{
	int d;
	if (x1 > x2) {
		int z = x2; x2 = x1; x1 = z;
	}
	for (d = x1; d <= x2; d++)
		file.pic[d][y] = c;
}
void draw_vline(int x, int y1, int y2, char c)
{
	int d;
	if (y1 > y2) {
		int z = y2; y2 = y1; y1 = z;
	}
	for (d = y1; d <= y2; d++)
		file.pic[x][d] = c;
}
void draw_frec(int x1, int x2, int y1, int y2, char c)
{
	int dx, dy;

	if (x1 > x2) {
		int z = x2; x2 = x1; x1 = z;
	}
	if (y1 > y2) {
		int z = y2; y2 = y1; y1 = z;
	}

	for (dx = x1; dx <= x2; dx++)
		for (dy = y1; dy <= y2; dy++)
			file.pic[dx][dy] = c;
}
char r = 0;
void fill(int x, int y, char c)
{
	if ((file.pic[x][y] != c) && !r)
		r = file.pic[x][y];

	if (file.pic[x][y] == r) {
		file.pic[x][y] = c;

		fill(x-1, y, c);
		fill(x, y+1, c);
		fill(x+1, y, c);
		fill(x, y-1, c);
	}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Find critical input

Post by brianfry713 » Wed Jul 24, 2013 11:45 pm

If as a command there will be a character different from I, C, L, V, H, K, F, S, X, the editor should ignore the whole line and pass to the next command.
Check input and AC output for thousands of problems on uDebug!

aybek
New poster
Posts: 19
Joined: Fri Jul 19, 2013 10:25 am
Contact:

Re: Find critical input

Post by aybek » Thu Jul 25, 2013 1:56 pm

I corrected this but still getting WA. :D

Code: Select all

#include <stdio.h>
#include <ctype.h>

#define MAXX 252
#define MAXY 252

#define CREATE_IMAGE	'I'
#define CLEAR_IMAGE		'C'
#define DRAW_PIXEL		'L'
#define DRAW_VLINE		'V'
#define DRAW_HLINE		'H'
#define DRAW_FREC		'K'
#define FILL			'F'
#define SAVE_IMAGE		'S'
#define CLOSE_PROG		'X'


struct image {
	int M, N;
	char title[20];
	char pic[MAXX][MAXY];
};

struct image file;

void create_image(void);
void save_image(void);
void clear_image(void);
void draw_pixel(int, int, char);
void draw_hline(int, int, int, char);
void draw_vline(int, int, int, char);
void draw_frec(int, int, int, int, char);
void fill(int, int, char, int);

int main()
{
	char command;
	char c; int x, y, x1, x2, y1, y2;

	for (x = 0; x < MAXX; x++)
		for (y = 0; y < MAXY; y++)
			file.pic[x][y] = 0;

	while (1) {
		scanf("%c ", &command);

		if (command == CLOSE_PROG)
			break;

		switch (command) {
			case CREATE_IMAGE :
				scanf("%d %d\n", &file.M, &file.N);
				create_image();
				break;

			case CLEAR_IMAGE :
				clear_image();
				break;
			case DRAW_PIXEL :
				scanf("%d %d %c\n", &x, &y, &c);
				draw_pixel(x, y, c);
				break;
			case DRAW_VLINE :
				scanf("%d %d %d %c\n", &x, &y1, &y2, &c);
				draw_vline(x, y1, y2, c);
				break;
			case DRAW_HLINE :
				scanf("%d %d %d %c\n", &x1, &x2, &y, &c);
				draw_hline(x1, x2, y, c);
				break;
			case DRAW_FREC :
				scanf("%d %d %d %d %c\n", &x1, &x2, &y1, &y2, &c);
				draw_frec(x1, x2, y1, y2, c);
				break;
			case FILL :
				scanf("%d %d %c\n", &x, &y, &c);
				fill(x, y, c, 0);
				break;

			case SAVE_IMAGE :
				scanf("%s\n", (file.title));
				save_image();
				break;
			default :
				while ((command = getchar()) != '\n');
				break;
		}
	}

	return 0;
}

void create_image(void)
{
	int i, j;

	for (i = 1; i <= file.M; i++)
		for (j = 1; j <= file.N; j++)
			file.pic[i][j] = 'O';
}
void save_image(void)
{
	int i, j;

	printf("%s\n", file.title);
	for (i = 1; i <= file.M; i++) {
		for (j = 1; j <= file.N; j++)
			printf("%c", file.pic[j][i]);
		printf("\n");
	}
}
void clear_image(void)
{
	int i, j;
	for (i = 1; i <= file.M; i++)
		for (j = 1; j <= file.N; j++)
			file.pic[i][j] = 'O';
}
void draw_pixel(int x, int y, char c)
{
	file.pic[x][y] = c;
}
void draw_hline(int x1, int x2, int y, char c)
{
	int d;
	if (x1 > x2) {
		int z = x2; x2 = x1; x1 = z;
	}
	for (d = x1; d <= x2; d++)
		file.pic[d][y] = c;
}
void draw_vline(int x, int y1, int y2, char c)
{
	int d;
	if (y1 > y2) {
		int z = y2; y2 = y1; y1 = z;
	}
	for (d = y1; d <= y2; d++)
		file.pic[x][d] = c;
}
void draw_frec(int x1, int x2, int y1, int y2, char c)
{
	int dx, dy;

	if (x1 > x2) {
		int z = x2; x2 = x1; x1 = z;
	}
	if (y1 > y2) {
		int z = y2; y2 = y1; y1 = z;
	}

	for (dx = x1; dx <= x2; dx++)
		for (dy = y1; dy <= y2; dy++)
			file.pic[dx][dy] = c;
}
void fill(int x, int y, char c, int flag)
{
	if ((file.pic[x][y] != c) && !flag)
		flag = file.pic[x][y];

	if (file.pic[x][y] == flag) {
		file.pic[x][y] = c;

		fill(x-1, y, c, flag);
		fill(x, y+1, c, flag);
		fill(x+1, y, c, flag);
		fill(x, y-1, c, flag);
	}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Find critical input

Post by brianfry713 » Sat Jul 27, 2013 4:15 am

Input:

Code: Select all

I 5 5
I 4 4
H 1 4 2 X
S one.bmp
F 1 1 Z
S two.bmp
X
AC output:

Code: Select all

one.bmp
OOOO
XXXX
OOOO
OOOO
two.bmp
ZZZZ
XXXX
OOOO
OOOO
Check input and AC output for thousands of problems on uDebug!

Zyaad Jaunnoo
Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

Re: 10267 - Graphical Editor

Post by Zyaad Jaunnoo » Fri Aug 16, 2013 2:56 am

I got a few Runtime Error for my code before finally getting AC.

A couple of tips:
1) I completely forgot to handle the situation when the program tries to fill a region of the same color as the current pixel.

2) I also tried to use both queues for floodfill and recursion. They both gave AC.

Ra1nWarden
New poster
Posts: 2
Joined: Sun Sep 15, 2013 3:49 am

Re: 10267 - Graphical Editor

Post by Ra1nWarden » Sun Sep 15, 2013 3:59 am

Hi Bryanfry, I am getting
WGJGGGGGGW
instead of
OGjGGGGGGW
I went through the commands manually and found the same result as "WGJGGGGGGW ".
Can someone explain to me what is happening here? Thanks!

Post Reply

Return to “Volume 102 (10200-10299)”