I already tested examples
but didn't find difference.
result of my program is exactly same.
I got W.A

Thanks Darko
Moderator: Board moderators
Code: Select all
/*
runtime error;
vc6.0 : I 150+ 150+, F X Y COLOR => EXCEPTION !
BUT cygwin -> not exception;
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int row, col;
char table[251][251];
char color, color2;
void myfunc(int x, int y) {
table[y][x] = color;
if ((x+1 <= col) && (table[y][x+1] == color2)) {
myfunc(x+1, y);
}
if ((x-1 >= 1) && (table[y][x-1] == color2)) {
myfunc(x-1, y);
}
if ((y+1 <= row) && (table[y+1][x] == color2)) {
myfunc(x, y+1);
}
if ((y-1 >= 1) && (table[y-1][x] == color2)) {
myfunc(x, y-1);
}
}
void main()
{
char buf[82];
char filename[13];
int i, j;
char cmd;
int x, y;
int x1, y1, x2, y2;
int temp;
int flag = 1;
while (flag && fgets(buf, sizeof(buf), stdin)) {
switch (buf[0]) {
case 'I':
sscanf(buf, "%c %d %d", &cmd, &col, &row);
/* no break; */
case 'C':
for (i=1; i<=row; i++) {
for (j=1; j<=col; j++) {
table[i][j] = 'O';
}
}
break;
case 'L':
sscanf(buf, "%c %d %d %c", &cmd, &x, &y, &color);
table[y][x] = color;
break;
case 'V':
sscanf(buf, "%c %d %d %d %c", &cmd, &x, &y1, &y2, &color);
if (y1 > y2) {
temp = y1;
y1 = y2;
y2 = temp;
}
for (i=y1; i<=y2; i++) table[i][x] = color;
break;
case 'H':
sscanf(buf, "%c %d %d %d %c", &cmd, &x1, &x2, &y, &color);
if (x1 > x2) {
temp = x1;
x1 = x2;
x2 = temp;
}
for (i=x1; i<=x2; i++) table[y][i] = color;
break;
case 'K':
sscanf(buf, "%c %d %d %d %d %c", &cmd, &x1, &y1, &x2, &y2, &color);
for (i=y1; i<=y2; i++)
for (j=x1; j<=x2; j++)
table[i][j] = color;
break;
case 'F':
sscanf(buf, "%c %d %d %c", &cmd, &x, &y, &color);
color2 = table[y][x];
myfunc(x, y);
break;
case 'S':
sscanf(buf, "%c %s", &cmd, filename);
printf("%s\n", filename);
for (i=1; i<=row; i++) {
for (j=1; j<=col; j++) {
printf("%c", table[i][j]);
}
printf("\n");
}
break;
case 'X':
flag = 0;
break;
default:
break;
}
}
}
Code: Select all
void fill(int i,int j,char color) {
char oldcolor = M[i][j];
if(oldcolor==color)
return;
M[i][j]=color;
for(int k=0; k<4; k++) {
int ii=i+di[k],jj=j+dj[k];
if(ii>=0&&ii<m&&jj>=0&&jj<n&&M[ii][jj]==oldcolor)
fill(ii,jj,color);
}
}
Code: Select all
I 5 6
L 2 3 A
S one.bmp
G 2 3 J
F 3 3 J
V 2 3 4 W
H 3 4 2 Z
F 3 3 J
S two.bmp
X
Code: Select all
one.bmp
OOOOO
OOOOO
OAOOO
OOOOO
OOOOO
OOOOO
two.bmp
JJJJJ
JJZZJ
JWJJJ
JWJJJ
JJJJJ
JJJJJ
Code: Select all
flag = true;
do
{
cin >> comm;
if( comm == 'X' )
flag = false;
if( flag && comm != ' ' ) // process the command, the ' ' is because the text for the //problem says: ... "in the very beginning of the line" so I //thought they are using "non-valid" space-started command lines...
{
//here goes the switch - case...
}
}while( flag );
Code: Select all
case 'L':
cin >> y >> x >> color;
image[x-1][y-1]= color;
break;
Code: Select all
image[y-1][x-1] = color;
Code: Select all
- By definition (X,Y) belongs to R.
---> then let's create a vector which holds this pixel, this vector is called R
do
{
- Now, every pixel, sharing sides with at least one of the pixels in R and being the same color, belongs to R. But.... not so fast, let's create another vector, called "conexos" (It's spanish, I'm Colombian :D ) in which I will store the pixels who share one side with at least one of the pixels stored in R, and have the same color, of course.
- Let's fill the pixels stored in R. For every pixel stored in R, perform a single-pixel fill.
- Empty R.
- Swap the data between R and conexos.
} while( R.size > 0 );
Code: Select all
.......
...n...
..nRn..
...n...
.......
Code: Select all
.......
..nn...
..nR...
.......
.......