## 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

tomtom85
New poster
Posts: 5
Joined: Tue Jun 01, 2010 7:48 am

### Re: 10267 - Graphical Editor

Hello, i have been reading all the post in general, i have checked all the posible mistakes and i keep getting WA. If anybody could check my code and point an error i will be very gratefull.
here it is!

Code: Select all

``````#include <stdio.h>
int M=0,N=0,matrix[252][252];

int getInt(char a){
return ((int)a-48);
}

int getMenor(int x, int y){
if(x>y)
return y;
return x;
}
int getMayor(int x, int y){
if(x>y)
return x;
return y;
}
int f_inst(char original,char replace,int x,int y){
if (matrix[x][y] == original){
matrix[x][y] = replace;
if(x<M && matrix[x+1][y] != replace)   f_inst(original,replace,x+1,y);
if(x>0 && matrix[x-1][y] != replace)   f_inst(original,replace,x-1,y);
if(y<N && matrix[x][y+1] != replace)   f_inst(original,replace,x,y+1);
if(y>0 && matrix[x][y-1] != replace)   f_inst(original,replace,x,y-1);
return 1;
}
return 0;
}

int isValid(int x,int y){

if (x>0 && x <= M && y > 0 && y<= N)
return 1;
return 0;
}

int isValidSize(int x,int y){
if (x>0 && x<=252 && y>0 && y<=252)
return 1;
return 0;
}

int main(){

//freopen("file2.in","rt",stdin);
char inst[256],c,name[13];
int i,j,x1,x2,y1,y2,m,n;

fgets(inst,256,stdin);
while(inst[0] != 'X'){
switch(inst[0]){

case 'I':
sscanf(inst,"%*c %d%d",&m,&n);
if(isValidSize(m,n)){
M=m;
N=n;
}
case 'C':
for (j=0;j<=N;j++)
for(i=0;i<=M;i++)
matrix[i][j] = 'O';
break;
case 'L':
sscanf(inst,"%*c %d%d %c",&x1,&y1,&c);
if(isValid(x1,y1))
matrix[x1-1][y1-1] = c;
break;
case 'V':
sscanf(inst,"%*c%d%d%d %c",&x1,&y1,&y2,&c);
if ((isValid(x1,y1) + isValid(x1,y2)) == 2){
for (i=getMenor(y1,y2)-1;i<getMayor(y1,y2);i++)
matrix[x1-1][i] = c;
}
break;
case 'H':
sscanf(inst,"%*c%d%d%d %c",&x1,&x2,&y1,&c);
if ((isValid(x1,y1) + isValid(x2,y1)) == 2){
for (i=getMenor(x1,x2)-1;i<getMayor(x1,x2);i++)
matrix[i][y1-1] = c;
}
break;
case 'F':
sscanf(inst,"%*c%d%d %c",&x1,&y1,&c);
if(isValid(x1,y1))
f_inst(matrix[x1-1][y1-1],c,x1-1,y1-1);
break;
case 'K':
sscanf(inst,"%*c%d%d%d%d %c",&x1,&y1,&x2,&y2,&c);
if ((isValid(x1,y1) + isValid(x2,y2)) == 2){
for (j=getMenor(y1,y2)-1;j<getMayor(y1,y2);j++)
for (i=getMenor(x1,x2)-1;i<getMayor(x1,x2);i++)
matrix[i][j] = c;
}
break;
case 'S':
sscanf(inst,"%*c %s",&name);
printf("%s\n",name);
for (j=0;j<N;j++){
for (i=0;i<M;i++)
printf("%c",matrix[i][j]);
printf("\n");
}
break;
default:
break;
}

fgets(inst,256,stdin);
}
return 0;
}
``````

tomtom85
New poster
Posts: 5
Joined: Tue Jun 01, 2010 7:48 am

### Re: 10267 - Graphical Editor

tomtom85 wrote:Hello, i have been reading all the post in general, i have checked all the posible mistakes and i keep getting WA. If anybody could check my code and point an error i will be very gratefull.
here it is!

Code: Select all

``````#include <stdio.h>
int M=0,N=0,matrix[252][252];

int getInt(char a){
return ((int)a-48);
}

int getMenor(int x, int y){
if(x>y)
return y;
return x;
}
int getMayor(int x, int y){
if(x>y)
return x;
return y;
}
int f_inst(char original,char replace,int x,int y){
if (matrix[x][y] == original){
matrix[x][y] = replace;
if(x<M && matrix[x+1][y] != replace)   f_inst(original,replace,x+1,y);
if(x>0 && matrix[x-1][y] != replace)   f_inst(original,replace,x-1,y);
if(y<N && matrix[x][y+1] != replace)   f_inst(original,replace,x,y+1);
if(y>0 && matrix[x][y-1] != replace)   f_inst(original,replace,x,y-1);
return 1;
}
return 0;
}

int isValid(int x,int y){

if (x>0 && x <= M && y > 0 && y<= N)
return 1;
return 0;
}

int isValidSize(int x,int y){
if (x>0 && x<=252 && y>0 && y<=252)
return 1;
return 0;
}

int main(){

//freopen("file2.in","rt",stdin);
char inst[256],c,name[13];
int i,j,x1,x2,y1,y2,m,n;

fgets(inst,256,stdin);
while(inst[0] != 'X'){
switch(inst[0]){

case 'I':
sscanf(inst,"%*c %d%d",&m,&n);
if(isValidSize(m,n)){
M=m;
N=n;
}
case 'C':
for (j=0;j<=N;j++)
for(i=0;i<=M;i++)
matrix[i][j] = 'O';
break;
case 'L':
sscanf(inst,"%*c %d%d %c",&x1,&y1,&c);
if(isValid(x1,y1))
matrix[x1-1][y1-1] = c;
break;
case 'V':
sscanf(inst,"%*c%d%d%d %c",&x1,&y1,&y2,&c);
if ((isValid(x1,y1) + isValid(x1,y2)) == 2){
for (i=getMenor(y1,y2)-1;i<getMayor(y1,y2);i++)
matrix[x1-1][i] = c;
}
break;
case 'H':
sscanf(inst,"%*c%d%d%d %c",&x1,&x2,&y1,&c);
if ((isValid(x1,y1) + isValid(x2,y1)) == 2){
for (i=getMenor(x1,x2)-1;i<getMayor(x1,x2);i++)
matrix[i][y1-1] = c;
}
break;
case 'F':
sscanf(inst,"%*c%d%d %c",&x1,&y1,&c);
if(isValid(x1,y1))
f_inst(matrix[x1-1][y1-1],c,x1-1,y1-1);
break;
case 'K':
sscanf(inst,"%*c%d%d%d%d %c",&x1,&y1,&x2,&y2,&c);
if ((isValid(x1,y1) + isValid(x2,y2)) == 2){
for (j=getMenor(y1,y2)-1;j<getMayor(y1,y2);j++)
for (i=getMenor(x1,x2)-1;i<getMayor(x1,x2);i++)
matrix[i][j] = c;
}
break;
case 'S':
sscanf(inst,"%*c %s",&name);
printf("%s\n",name);
for (j=0;j<N;j++){
for (i=0;i<M;i++)
printf("%c",matrix[i][j]);
printf("\n");
}
break;
default:
break;
}

fgets(inst,256,stdin);
}
return 0;
}
``````
Here is an upgrade from my code, its still wrong but much much more fast and understandable, so any help will come handy.

Code: Select all

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

#define MSIZE 251

char matrix[MSIZE][MSIZE];
int M,N;//M -> Columns (X); N->Rows (Y)

int fill(int x,int y,char color,char origin){

matrix[x][y] = color;
if (y+1 < N && matrix[x][y+1] == origin) fill(x,y+1,color,origin);
if (y-1 >= 0 && matrix[x][y-1] == origin) fill(x,y-1,color,origin);
if (x+1 < M && matrix[x+1][y] == origin) fill(x+1,y,color,origin);
if (x-1 >= 0 && matrix[x-1][y] == origin) fill(x-1,y,color,origin);

return 1;
}

int swap(int *min, int *max){
int temp,m = *min,m2 = *max;
if (m > m2){
temp = *max;
*max = *min;
*min = temp;
return 1;
}
return 0;
}

int validateColumn(int x){
if(x>0 && x<=M)
return 1;
return 0;
}

int validateRow(int y){
if(y>0 && y<=N)
return 1;
return 0;
}

int main(){

char code,color,name[13];
int x1,y1,x2,y2,m,n;

freopen("file2.in","rt",stdin);

scanf("%c",&code);

while(code != 'X'){

switch(code){

case 'L':
scanf("%d%d %c\n",&x1,&y1,&color);
if((validateColumn(x1) + validateRow(y1)) == 2)
x1--; y1--;
matrix[x1][y1] = color;
break;
case 'V':
scanf("%d%d%d %c\n",&x1,&y1,&y2,&color);
if((validateColumn(x1) + validateRow(y1) + validateRow(y2)) == 3){
x1--; y1--;y2--;
swap(&y1,&y2);
for(n=y1;n<=y2;n++)
matrix[x1][n]=color;
}
break;
case 'H':
scanf("%d%d%d %c\n",&x1,&x2,&y1,&color);
if((validateColumn(x1) + validateColumn(x2) + validateRow(y1)) == 3){
x1--; x2--;y1--;
swap(&x1,&x2);
for(m=x1;m<=x2;m++)
matrix[m][y1]=color;
}
break;
case 'K':
scanf("%d%d%d%d %c\n",&x1,&y1,&x2,&y2,&color);
if((validateColumn(x1) + validateColumn(x2) + validateRow(y1)+ validateRow(y2)) == 4){
x1--;x2--;y1--;y2--;
swap(&x1,&x2); swap(&y1,&y2);
for(m=x1;m<=x2;m++)
for(n=y1;n<=y2;n++)
matrix[m][n] = color;
}
break;
case 'F':
scanf("%d%d %c\n",&x1,&y1,&color);
if((validateColumn(x1) + validateRow(y1)) == 2){
x1--;y1--;
if (matrix[x1][y1] == color) break;

fill(x1,y1,color,matrix[x1][y1]);
}
break;
case 'I':
scanf("%d%d\n",&M,&N);
case 'C':
for(n=0;n<N;n++)
for(m=0;m<M;m++)
matrix[m][n] = 'O';
break;
case 'S':
scanf("%s\n",&name);
printf("%s\n",name);
for(n=0;n<N;n++){
for(m=0;m<M;m++)
printf("%c",matrix[m][n]);
printf("\n");
}
break;
default:
while(1){
scanf("%c",&code);
if (code == '\n')
break;
}
scanf("\n");
break;

}
scanf("%c",&code);
}
return 0;
}
``````

tomtom85
New poster
Posts: 5
Joined: Tue Jun 01, 2010 7:48 am

### Re: 10267 - Graphical Editor

tomtom85 wrote:
tomtom85 wrote:Hello, i have been reading all the post in general, i have checked all the posible mistakes and i keep getting WA. If anybody could check my code and point an error i will be very gratefull.
here it is!

Code: Select all

``````#include <stdio.h>
int M=0,N=0,matrix[252][252];

int getInt(char a){
return ((int)a-48);
}

int getMenor(int x, int y){
if(x>y)
return y;
return x;
}
int getMayor(int x, int y){
if(x>y)
return x;
return y;
}
int f_inst(char original,char replace,int x,int y){
if (matrix[x][y] == original){
matrix[x][y] = replace;
if(x<M && matrix[x+1][y] != replace)   f_inst(original,replace,x+1,y);
if(x>0 && matrix[x-1][y] != replace)   f_inst(original,replace,x-1,y);
if(y<N && matrix[x][y+1] != replace)   f_inst(original,replace,x,y+1);
if(y>0 && matrix[x][y-1] != replace)   f_inst(original,replace,x,y-1);
return 1;
}
return 0;
}

int isValid(int x,int y){

if (x>0 && x <= M && y > 0 && y<= N)
return 1;
return 0;
}

int isValidSize(int x,int y){
if (x>0 && x<=252 && y>0 && y<=252)
return 1;
return 0;
}

int main(){

//freopen("file2.in","rt",stdin);
char inst[256],c,name[13];
int i,j,x1,x2,y1,y2,m,n;

fgets(inst,256,stdin);
while(inst[0] != 'X'){
switch(inst[0]){

case 'I':
sscanf(inst,"%*c %d%d",&m,&n);
if(isValidSize(m,n)){
M=m;
N=n;
}
case 'C':
for (j=0;j<=N;j++)
for(i=0;i<=M;i++)
matrix[i][j] = 'O';
break;
case 'L':
sscanf(inst,"%*c %d%d %c",&x1,&y1,&c);
if(isValid(x1,y1))
matrix[x1-1][y1-1] = c;
break;
case 'V':
sscanf(inst,"%*c%d%d%d %c",&x1,&y1,&y2,&c);
if ((isValid(x1,y1) + isValid(x1,y2)) == 2){
for (i=getMenor(y1,y2)-1;i<getMayor(y1,y2);i++)
matrix[x1-1][i] = c;
}
break;
case 'H':
sscanf(inst,"%*c%d%d%d %c",&x1,&x2,&y1,&c);
if ((isValid(x1,y1) + isValid(x2,y1)) == 2){
for (i=getMenor(x1,x2)-1;i<getMayor(x1,x2);i++)
matrix[i][y1-1] = c;
}
break;
case 'F':
sscanf(inst,"%*c%d%d %c",&x1,&y1,&c);
if(isValid(x1,y1))
f_inst(matrix[x1-1][y1-1],c,x1-1,y1-1);
break;
case 'K':
sscanf(inst,"%*c%d%d%d%d %c",&x1,&y1,&x2,&y2,&c);
if ((isValid(x1,y1) + isValid(x2,y2)) == 2){
for (j=getMenor(y1,y2)-1;j<getMayor(y1,y2);j++)
for (i=getMenor(x1,x2)-1;i<getMayor(x1,x2);i++)
matrix[i][j] = c;
}
break;
case 'S':
sscanf(inst,"%*c %s",&name);
printf("%s\n",name);
for (j=0;j<N;j++){
for (i=0;i<M;i++)
printf("%c",matrix[i][j]);
printf("\n");
}
break;
default:
break;
}

fgets(inst,256,stdin);
}
return 0;
}
``````
Here is an upgrade from my code, its still wrong but much much more fast and understandable, so any help will come handy.

Code: Select all

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

#define MSIZE 251

char matrix[MSIZE][MSIZE];
int M,N;//M -> Columns (X); N->Rows (Y)

int fill(int x,int y,char color,char origin){

matrix[x][y] = color;
if (y+1 < N && matrix[x][y+1] == origin) fill(x,y+1,color,origin);
if (y-1 >= 0 && matrix[x][y-1] == origin) fill(x,y-1,color,origin);
if (x+1 < M && matrix[x+1][y] == origin) fill(x+1,y,color,origin);
if (x-1 >= 0 && matrix[x-1][y] == origin) fill(x-1,y,color,origin);

return 1;
}

int swap(int *min, int *max){
int temp,m = *min,m2 = *max;
if (m > m2){
temp = *max;
*max = *min;
*min = temp;
return 1;
}
return 0;
}

int validateColumn(int x){
if(x>0 && x<=M)
return 1;
return 0;
}

int validateRow(int y){
if(y>0 && y<=N)
return 1;
return 0;
}

int main(){

char code,color,name[13];
int x1,y1,x2,y2,m,n;

freopen("file2.in","rt",stdin);

scanf("%c",&code);

while(code != 'X'){

switch(code){

case 'L':
scanf("%d%d %c\n",&x1,&y1,&color);
if((validateColumn(x1) + validateRow(y1)) == 2)
x1--; y1--;
matrix[x1][y1] = color;
break;
case 'V':
scanf("%d%d%d %c\n",&x1,&y1,&y2,&color);
if((validateColumn(x1) + validateRow(y1) + validateRow(y2)) == 3){
x1--; y1--;y2--;
swap(&y1,&y2);
for(n=y1;n<=y2;n++)
matrix[x1][n]=color;
}
break;
case 'H':
scanf("%d%d%d %c\n",&x1,&x2,&y1,&color);
if((validateColumn(x1) + validateColumn(x2) + validateRow(y1)) == 3){
x1--; x2--;y1--;
swap(&x1,&x2);
for(m=x1;m<=x2;m++)
matrix[m][y1]=color;
}
break;
case 'K':
scanf("%d%d%d%d %c\n",&x1,&y1,&x2,&y2,&color);
if((validateColumn(x1) + validateColumn(x2) + validateRow(y1)+ validateRow(y2)) == 4){
x1--;x2--;y1--;y2--;
swap(&x1,&x2); swap(&y1,&y2);
for(m=x1;m<=x2;m++)
for(n=y1;n<=y2;n++)
matrix[m][n] = color;
}
break;
case 'F':
scanf("%d%d %c\n",&x1,&y1,&color);
if((validateColumn(x1) + validateRow(y1)) == 2){
x1--;y1--;
if (matrix[x1][y1] == color) break;

fill(x1,y1,color,matrix[x1][y1]);
}
break;
case 'I':
scanf("%d%d\n",&M,&N);
case 'C':
for(n=0;n<N;n++)
for(m=0;m<M;m++)
matrix[m][n] = 'O';
break;
case 'S':
scanf("%s\n",&name);
printf("%s\n",name);
for(n=0;n<N;n++){
for(m=0;m<M;m++)
printf("%c",matrix[m][n]);
printf("\n");
}
break;
default:
while(1){
scanf("%c",&code);
if (code == '\n')
break;
}
scanf("\n");
break;

}
scanf("%c",&code);
}
return 0;
}
``````
Ok... all the problem was the comments, dont do // coments! damn!

chackal_sjc
New poster
Posts: 2
Joined: Wed Jun 09, 2010 5:53 am

### Re: 10267 - Graphical Editor

Dude,

I'm getting WA but all my inputs are correct ... does someone have a really good input to test?

Thank you
UNIFEI - Universidade Federal de Itajubá, Brazil

qweasdf_123
New poster
Posts: 2
Joined: Sun Nov 28, 2010 11:03 am

### Re: 10267 - Graphical Editor

Hi everybody,i always get WA.But my code is perfect and works fine.Please,help me.Where is my fault.I' be very very pleased.

public class Main{
// 110105/10267/Graphical Editor
public static void main(String[] args) throws IOException{
new Main().run();
}
private PrintWriter out;
private Scanner in;
private char[][] a=new char[250][250];
private int n=0,m=0, i=0,i1=0,i2=0, j=0,j1=0,j2=0;
private char color='O';

void run() throws IOException{
// in = new Scanner(new File("src/input.txt"));
// out = new PrintWriter(new File("src/output.txt"));

in = new Scanner(System.in);
out = new PrintWriter(System.out,true);

solve();

in.close();
out.close();
}
void solve() throws IOException{
int cnt=0;
while(in.hasNextLine()){
String cmdLine=in.nextLine().trim();
String params[]=cmdLine.split(" ");
char cmd=cmdLine.charAt(0);

switch(cmd){
case 'I':
m=Integer.parseInt(params[1]);
n=Integer.parseInt(params[2]);
a=new char[n][m];
for(int t=0;t<n;t++)
for(int k=0;k<m;k++)
a[t][k]='O';
break;
case 'C':
// c
for(int t=0;t<n;t++)
for(int k=0;k<m;k++)
a[t][k]='O';
break;
case 'L':
// l x y c
j=Integer.parseInt(params[1])-1;
i=Integer.parseInt(params[2])-1;
color=params[3].charAt(0);
a[j]=color;
break;
case 'V':
// v x y1 y2 c
j=Integer.parseInt(params[1])-1;
i1=Integer.parseInt(params[2])-1;
i2=Integer.parseInt(params[3])-1;
color=params[4].charAt(0);
for(int t=Math.min(i1,i2);t<=Math.max(i1,i2);t++)
a[t][j]=color;
break;
case 'H':
// h x1 x2 y c
j1=Integer.parseInt(params[1])-1;
j2=Integer.parseInt(params[2])-1;
i=Integer.parseInt(params[3])-1;
color=params[4].charAt(0);
for(int k=Math.min(j1,j2);k<=Math.max(j1,j2);k++)
a[k]=color;
break;
case 'K':
// k x1 y1 x2 y2 c
j1=Integer.parseInt(params[1])-1;
i1=Integer.parseInt(params[2])-1;
j2=Integer.parseInt(params[3])-1;
i2=Integer.parseInt(params[4])-1;
color=params[5].charAt(0);
for(int t=Math.min(i1,i2);t<=Math.max(i1,i2);t++)
for(int k=Math.min(j1,j2);k<=Math.max(j1,j2);k++)
a[t][k]=color;
break;
case 'F':
// f x y c
i=Integer.parseInt(params[1])-1;
j=Integer.parseInt(params[2])-1;
color=params[3].charAt(0);
char oldColor=a[j];
if(color==oldColor)
break;

int curr=0;
Vector<Pixel> q=new Vector<Pixel>();// queue
boolean[][] used=new boolean[n][m];
used[j]=true;
while(curr<q.size()){
i=q.get(curr).i;
j=q.get(curr).j;
for(int t=i-1;t<=i+1;t++)
for(int k=j-1;k<=j+1;k++)
if(t<n && t>=0 && k<m && k>=0 && (t==i||k==j) && !used[t][k] && a[t][k]==oldColor){
used[t][k]=true;
}
a[j]=color;
curr++;
}
break;
case 'S':
// s name
cnt++;
String fileName=params[1];
if(cnt>1)
out.println();
out.println(fileName);
for(int t=0;t<n;t++){
for(int k=0;k<m;k++)
out.print(a[t][k]);
if(t<n-1)
out.println();
}
break;
case 'X':
return;
default:
break;
}
}
}
class Pixel{
int i, j;
Pixel(int i,int j){
this.i=i;
this.j=j;
}
}
}

tnaires
New poster
Posts: 10
Joined: Mon Mar 07, 2005 6:22 pm
Location: Natal - RN / Brazil

### 10267 - WA

Good evening!

I'm getting WA in this problem, here's my code:

Code: Select all

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

#define CMD_LENGTH 50
#define ARG_LENGTH 5
#define DELIMITERS " \n"
#define TABLE_SIZE 250
#define DEFAULT_COLOR 'O'
#define FILENAME_LENGTH 12

typedef struct _table {
char pixels[TABLE_SIZE][TABLE_SIZE];
int rows, cols;
} table;

table C(table t) {
int i, j;

for (i = 0; i < t.rows; i++) {
for (j = 0; j < t.cols; j++) {
t.pixels[i][j] = DEFAULT_COLOR;
}
}

return t;
}

table I(int m, int n) {
table result;
result.rows = n;
result.cols = m;

return C(result);
}

table L(table t, int x, int y, char c) {
t.pixels[y - 1][x - 1] = c;
return t;
}

table K(table t, int x1, int y1, int x2, int y2, char c) {
int xleft, xright;

if (x1 < x2) {
xleft = x1;
xright = x2;
} else {
xleft = x2;
xright = x1;
}

int ytop, ybottom;

if (y1 < y2) {
ytop = y1;
ybottom = y2;
} else {
ytop = y2;
ybottom = y1;
}

int i, j;

for (i = xleft - 1; i < xright; i++) {
for (j = ytop - 1; j < ybottom; j++) {
t.pixels[j][i] = c;
}
}

return t;
}

table V(table t, int x, int y1, int y2, char c) {
return K(t, x, y1, x, y2, c);
}

table H(table t, int x1, int x2, int y, char c) {
return K(t, x1, y, x2, y, c);
}

table copy(table t) {
table result;
result.rows = t.rows;
result.cols = t.cols;
int i, j;

for (i = 0; i < t.rows; i++) {
for (j = 0; j < t.cols; j++) {
result.pixels[i][j] = t.pixels[i][j];
}
}

return result;
}

table F(table t, int x, int y, char c) {
table original = copy(t);
x -= 1;
y -= 1;
t.pixels[y][x] = c;
int search = 1, painted;

do {
painted = 0;

int sx1 = x - search;
int sx2 = x + search;
int sy1 = y - search;
int sy2 = y + search;
int i;

for (i = sy1; i <= sy2; i++) {
if (sx1 >= 0 && sx1 < t.cols && i >= 0 && i < t.rows) {
if (original.pixels[y][x] == t.pixels[i][sx1]) {
t.pixels[i][sx1] = c;
painted = 1;
}
}

if (sx2 >= 0 && sx2 < t.cols && i >= 0 && i < t.rows) {
if (original.pixels[y][x] == t.pixels[i][sx2]) {
t.pixels[i][sx2] = c;
painted = 1;
}
}
}

for (i = sx1; i <= sx2; i++) {
if (i >= 0 && i < t.cols && sy1 >= 0 && sy1 < t.rows) {
if (original.pixels[y][x] == t.pixels[sy1][i]) {
t.pixels[sy1][i] = c;
painted = 1;
}
}

if (i >= 0 && i < t.cols && sy2 >= 0 && sy2 < t.rows) {
if (original.pixels[y][x] == t.pixels[sy2][i]) {
t.pixels[sy2][i] = c;
painted = 1;
}
}
}

search++;
} while (painted);

return t;
}

void S(table t, char filename[]) {
int i, j;
char filename_dos[FILENAME_LENGTH + 1];

strncpy(filename_dos, filename, FILENAME_LENGTH);
printf("%s\n", filename_dos);

for (i = 0; i < t.rows; i++) {
for (j = 0; j < t.cols; j++) {
printf("%c", t.pixels[i][j]);
}

printf("\n");
}
}

int main() {
char line[CMD_LENGTH];
table t;

while (fgets(line, CMD_LENGTH, stdin)) {
char *token = strtok(line, DELIMITERS);
char cmd = token[0];

switch (cmd) {
case 'I':
case 'C':
case 'L':
case 'V':
case 'H':
case 'K':
case 'F':
case 'S':
case 'X':
break;
default:
continue;
}

char *args[5];
int arg_count = 0;

do {
token = strtok(NULL, DELIMITERS);

if (token) {
args[arg_count] = token;
arg_count++;
} else {
break;
}
} while (1 == 1);

switch (cmd) {
case 'I':
t = I(atoi(args[0]), atoi(args[1]));
break;
case 'C':
t = C(t);
break;
case 'L':
t = L(t, atoi(args[0]), atoi(args[1]), args[2][0]);
break;
case 'V':
t = V(t, atoi(args[0]), atoi(args[1]), atoi(args[2]), args[3][0]);
break;
case 'H':
t = H(t, atoi(args[0]), atoi(args[1]), atoi(args[2]), args[3][0]);
break;
case 'K':
t = K(t, atoi(args[0]), atoi(args[1]), atoi(args[2]), atoi(args[3]), args[4][0]);
break;
case 'F':
t = F(t, atoi(args[0]), atoi(args[1]), args[2][0]);
break;
case 'S':
S(t, args[0]);
break;
case 'X':
return 0;
break;
}
}

return 0;
}
``````
I already executed various test cases, but I can't understand what's wrong with my code... And I searched the forum for help, but couldn't solve it...
Can anybody give me a input for testing?

Thanks for helping! Best regards.
Tarso Nunes Aires
Natal/RN - Brazil

tnaires
New poster
Posts: 10
Joined: Mon Mar 07, 2005 6:22 pm
Location: Natal - RN / Brazil

### Re: 10267 - WA

Well... Still WA.

Does anybody have any test case? Sorry for bothering.
Tarso Nunes Aires
Natal/RN - Brazil

Spribo
New poster
Posts: 3
Joined: Mon Sep 06, 2010 2:07 pm

### 10267-Checked step-by-step the algorithm, still WA

Here is my code in C++ for this problem:

Code: Select all

``````#include <iostream>
#include <string>

using namespace std;

void execute(char cod);

char table[252][252], code;

int m, n, index_1, index_2;

int main()
{
for(index_1 = 0; index_1 <= 251 ; index_1++) for(index_2 = 0; index_2 <= 251; index_2++) table[index_1][index_2] = '\0';
cin >> code;
execute(code);
return 0;
}

void fill(int x, int y, char c, char temp)
{
table[y][x] = c;
if(table[y][x - 1] == temp) fill(x - 1, y, c, temp);
if(table[y][x + 1] == temp) fill(x + 1, y, c, temp);
if(table[y - 1][x] == temp) fill(x, y - 1, c, temp);
if(table[y + 1][x] == temp) fill(x, y + 1, c, temp);
}

void execute(char cod)
{
int x, y, y1, y2, x1, x2, inter;
char c;
string j, name;
switch(cod) {
case 'X': break;
case 'I':
cin >> m >> n;
for(index_1 = 0; index_1 <= 251; index_1++) for(index_2 = 0; index_2 <= 251; index_2++) table[index_1][index_2] = '\0';
for(index_1 = 1; index_1 <= n; index_1++) for(index_2 = 1; index_2 <= m; index_2++) table[index_1][index_2] = 'O';
break;
case 'C':
for(index_1 = 1; index_1 <= n; index_1++) for(index_2 = 1; index_2 <= m; index_2++) table[index_1][index_2] = 'O';
break;
case 'L':
cin >> x >> y >>  c;
table[y][x] = c;
break;
case 'V':
cin >> x >> y1 >> y2 >> c;
if(y1 > y2) { inter = y1; y1 = y2; y2 = inter; }
for(index_1 = y1; index_1 <= y2; index_1++) table[index_1][x] = c;
break;
case 'H':
cin >> x1 >> x2 >> y >> c;
if(x1 > x2) { inter = x1; x1 = x2; x2 = inter; }
for(index_2 = x1; index_2 <= x2; index_2++) table[y][index_2] = c;
break;
case 'K':
cin >> x1 >> y1 >> x2 >> y2 >> c;
if(y1 > y2) { inter = y1; y1 = y2; y2 = inter; }
if(x1 > x2) { inter = x1; x1 = x2; x2 = inter; }
for(index_1 = y1; index_1 <= y2; index_1++) for(index_2 = x1; index_2 <= x2; index_2++) table[index_1][index_2] = c;
break;
case 'F':
cin >> x >> y >> c;
fill(x, y, c, table[y][x]);
break;
case 'S':
getline(cin, name);
name.erase(0,1);
cout << name << endl;
for(index_1 = 1; index_1 <= n; index_1++) {
for(index_2 = 1; index_2 <= m; index_2++) cout << table[index_1][index_2];
cout << endl;
}
break;
default: getline(cin, j);
}
if(cod != 'X') { cin >> code; execute(code); }
}
``````
I have checked the algorithm step by step, trying everything I had read in other threads, but I am still getting WA. Any help or some input to find my mistake(s) will be greatly appreciated! Thanks in advance!

outsbook
New poster
Posts: 26
Joined: Fri Oct 28, 2011 2:42 am

### Re: 10267 - WA

In this problem, x1>x2 or y1>y2
so, you need if(x1>x2) then swap(x1,x2) and if(y1>y2) then swap(y1,y2)
try this

Input:

Code: Select all

``````I 5 6
L 2 3 A
L 3 4 A
F 2 3 B
S one.bmp
L 3 3 A
L 2 3 A
F 2 3 B
S two.bmp
C
S three.bmp
S four.jpeg
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``````
Output:

Code: Select all

``````one.bmp
OOOOO
OOOOO
OBOOO
OOAOO
OOOOO
OOOOO
two.bmp
OOOOO
OOOOO
OBBOO
OOBOO
OOOOO
OOOOO
three.bmp
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
four.jpeg
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
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
``````
I think now you got ACC.....ha..ha..ha
"Learning to love yourself is the greatest love of all" - Michael Masser and Linda Creed

darka
New poster
Posts: 1
Joined: Fri Dec 16, 2011 10:24 am

### Re: 10267 - Graphical Editor

I 've looked through the whole discussion and checked that I've made none of the errors you guys mentioned, but I still get Runtime error . Can someone help find my error ? Thanks in advance
Here is my code: ( I used a First In First Out queue for the floodfill )

Code: Select all

``````#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

long i,m,n,j,x,x2,y,y2,qend,qstart,queue[10000000][2];
char oldcolour,colour,comword,board[300][300];
string filename,temp;

void qin(int x3,int y3){

qend++;
queue[qend][0]=x3;
queue[qend][1]=y3;

}
void  qout(){

qstart++;
x=queue[qstart][0];
y=queue[qstart][1];

}
int main (){
m=0;
n=0;

while ( (cin >> comword)&&(comword != 'X') ){
switch (comword){
case 'I':

cin >> m >> n;
for (i=1;i<=m;i++)
for (j=1;j<=n;j++)
board[i][j] = 'O';

// Draw a "\$" rectangle outside the picture
for (i=0;i<=m+1;i++) { board[i][0]='\$'; board[i][n+1]='\$'; }
for (i=0;i<=n+1;i++) { board[0][i]='\$'; board[m+1][i]='\$'; }

getline(cin,temp);
break;
case 'C':
for (i=1;i<=m;i++)
for (j=1;j<=n;j++)
board[i][j] = 'O';
getline(cin,temp);
break;
case 'L':
cin >> x >> y >> colour;
board[x][y]=colour;

getline(cin,temp);
break;
case 'V':
cin >> x >> y >> y2 >> colour;
if (y > y2) { y=y+y2;y2=y-y2;y=y-y2;}

for (i=y;i<=y2;i++) board[x][i] = colour;

getline(cin,temp);
break;
case 'H':
cin >> x >> x2 >> y >> colour;
if (x > x2) { x=x+x2;x2=x-x2;x=x-x2;}

for (i=x;i<=x2;i++) board[i][y] = colour;

getline(cin,temp);
break;
case 'K':
cin >> x >> y >> x2 >> y2 >> colour;
if (y > y2) { y=y+y2;y2=y-y2;y=y-y2;}
if (x > x2) { x=x+x2;x2=x-x2;x=x-x2;}

for (i=x;i<=x2;i++)
for (j=y;j<=y2;j++)
board[i][j]=colour;

getline(cin,temp);
break;
case 'F':
cin >> x >> y >> colour;

qend=0;
qstart=0;
qin(x,y);

oldcolour=board[x][y];
board[x][y]=colour;

do{

qout();
for (i=0;i<=3;i++)
{
}
}
while (qstart<qend);

getline(cin,temp);
break;
case 'S':

cin >> filename;

cout << filename << endl;
for (i=1 ;i<=n;i++)
{
for(j=1;j<=m;j++)
cout << board[j][i];
cout << endl;
}
getline(cin,filename);
break;
default:
getline(cin,temp);
break;
}

}

}
``````

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

### Re: 10267 - Graphical Editor

darka, see what happens with an F command matching the pixel's current color.
Check input and AC output for thousands of problems on uDebug!

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

### 10267 - WA! Previous topics's test data can output correctly

I know it's not a good code at all, but I just want to know the very reason...
Hope the kind you can help me!~

P.S. in "_F" function: I used a stupid way - Scanning from the given element to the edge loop for 10 times.
e.g. ???
?????
????
?- Judge; ?- Centre;

Code: Select all

``````/*
Name: 10267 - Graphical Editor
Author: MewCatcher
Date: 01-11-12 16:32
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 Judge( int _X, int _Y, char Color, char ColorINTO )
{
/*printf( "Judge >> _X=%d _Y=%d DColor=%c INTO=%c\n", _X, _Y, Color, ColorINTO );
system( "PAUSE" );*/
int i;
bool Flag1/*Up*/, Flag2/*Down*/, Flag3/*Left*/, Flag4/*Right*/;
if( _X - 1 >= 0 ) Flag3 = true; else Flag3 = false;
if( _X + 1 < X ) Flag4 = true; else Flag4 = false;
if( _Y - 1 >= 0 ) Flag1 = true; else Flag1 = false;
if( _Y + 1 < Y ) Flag2 = true; else Flag2 = false;
if( Flag1 && P[ _Y - 1 ][ _X ] == Color ) P[ _Y - 1 ][ _X ] = ColorINTO;
if( Flag2 && P[ _Y + 1 ][ _X ] == Color ) P[ _Y + 1 ][ _X ] = ColorINTO;
if( Flag3 && P[ _Y ][ _X - 1 ] == Color ) P[ _Y ][ _X - 1 ] = ColorINTO;
if( Flag3 && P[ _Y ][ _X + 1 ] == Color ) P[ _Y ][ _X + 1 ] = ColorINTO;
return ;
}

void _F( int _X, int _Y, char Color )
{
int i, j;
_X --;
_Y --;
char Default = P[ _Y ][ _X ];
P[ _Y ][ _X ] = Color;
/*printf( "_F >> _X=%d _Y=%d\n", _X, _Y );*/
for( j = 0; j < 10; j ++ ) {
int LU[ 2 ] = { _Y, _X }, LD[ 2 ] = { _Y, _X }, RU[ 2 ] = { _Y, _X }, RD[ 2 ] = { _Y, _X };/*LeftUp[ y, x ], LeftDown, RightUp, RightDown*/
while( !( LU[ 0 ] == 0 && LU[ 1 ] == 0 && LD[ 0 ] == Y - 1 && LD[ 1 ] == 0 && RU[ 0 ] == 0 && RU[ 1 ] == X - 1 && RD[ 0 ] == Y - 1 && RD[ 1 ] == X - 1 ) ) {
for( i = LU[ 1 ]; i <= RU[ 1 ]; i ++ ) {
/*printf( "in1 >> _X=%d/%d _Y=%d\n", LU[ 0 ], LD[ 0 ], i );*/
if( P[ LU[ 0 ] ][ i ] == Color ) Judge( i, LU[ 0 ], Default, Color );
if( P[ LD[ 0 ] ][ i ] == Color ) Judge( i, LD[ 0 ], Default, Color );
}
for( i = LU[ 0 ]; i <= LD[ 0 ]; i ++ ) {
/*printf( "in2 >> _X=%d _Y=%d/%d\n", i, LU[ 1 ], RU[ 1 ] );*/
if( P[ i ][ LU[ 1 ] ] == Color ) Judge( LU[ 1 ], i, Default, Color );
if( P[ i ][ RU[ 1 ] ] == Color ) Judge( RU[ 1 ], i, Default, Color );
}
if( LU[ 1 ] - 1 >= 0 ) { LU[ 1 ] --; LD[ 1 ] --; }
if( LU[ 0 ] - 1 >= 0 ) { LU[ 0 ] --; RU[ 0 ] --; }
if( RD[ 1 ] + 1 < X ) { RD[ 1 ] ++; RU[ 1 ] ++; }
if( RD[ 0 ] + 1 < Y ) { RD[ 0 ] ++; LD[ 0 ] ++; }
}
/*system( "PAUSE" );*/
}
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{ }
}
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

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.

You should ignore the whole line, not just that character. For input:

Code: Select all

``````I 5 6
J K 1 5 2 1 X
S five.jpeg
X``````
Correct output:

Code: Select all

``````five.jpeg
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO``````
Check input and AC output for thousands of problems on uDebug!

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

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

Thank you!
You've got a point here!
but I change into this, is still WA!~
Please have a look, Thx!!!

Code: Select all

``````/*
Name: 10267 - Graphical Editor
Author: MewCatcher
Date: 01-11-12 16:32
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 Judge( int _X, int _Y, char Color, char ColorINTO )
{
/*printf( "Judge >> _X=%d _Y=%d DColor=%c INTO=%c\n", _X, _Y, Color, ColorINTO );
system( "PAUSE" );*/
int i;
bool Flag1/*Up*/, Flag2/*Down*/, Flag3/*Left*/, Flag4/*Right*/;
if( _X - 1 >= 0 ) Flag3 = true; else Flag3 = false;
if( _X + 1 < X ) Flag4 = true; else Flag4 = false;
if( _Y - 1 >= 0 ) Flag1 = true; else Flag1 = false;
if( _Y + 1 < Y ) Flag2 = true; else Flag2 = false;
if( Flag1 && P[ _Y - 1 ][ _X ] == Color ) P[ _Y - 1 ][ _X ] = ColorINTO;
if( Flag2 && P[ _Y + 1 ][ _X ] == Color ) P[ _Y + 1 ][ _X ] = ColorINTO;
if( Flag3 && P[ _Y ][ _X - 1 ] == Color ) P[ _Y ][ _X - 1 ] = ColorINTO;
if( Flag3 && P[ _Y ][ _X + 1 ] == Color ) P[ _Y ][ _X + 1 ] = ColorINTO;
return ;
}

void _F( int _X, int _Y, char Color )
{
int i, j;
_X --;
_Y --;
char Default = P[ _Y ][ _X ];
P[ _Y ][ _X ] = Color;
/*printf( "_F >> _X=%d _Y=%d\n", _X, _Y );*/
for( j = 0; j < 10; j ++ ) {
int LU[ 2 ] = { _Y, _X }, LD[ 2 ] = { _Y, _X }, RU[ 2 ] = { _Y, _X }, RD[ 2 ] = { _Y, _X };/*LeftUp[ y, x ], LeftDown, RightUp, RightDown*/
while( !( LU[ 0 ] == 0 && LU[ 1 ] == 0 && LD[ 0 ] == Y - 1 && LD[ 1 ] == 0 && RU[ 0 ] == 0 && RU[ 1 ] == X - 1 && RD[ 0 ] == Y - 1 && RD[ 1 ] == X - 1 ) ) {
for( i = LU[ 1 ]; i <= RU[ 1 ]; i ++ ) {
/*printf( "in1 >> _X=%d/%d _Y=%d\n", LU[ 0 ], LD[ 0 ], i );*/
if( P[ LU[ 0 ] ][ i ] == Color ) Judge( i, LU[ 0 ], Default, Color );
if( P[ LD[ 0 ] ][ i ] == Color ) Judge( i, LD[ 0 ], Default, Color );
}
for( i = LU[ 0 ]; i <= LD[ 0 ]; i ++ ) {
/*printf( "in2 >> _X=%d _Y=%d/%d\n", i, LU[ 1 ], RU[ 1 ] );*/
if( P[ i ][ LU[ 1 ] ] == Color ) Judge( LU[ 1 ], i, Default, Color );
if( P[ i ][ RU[ 1 ] ] == Color ) Judge( RU[ 1 ], i, Default, Color );
}
if( LU[ 1 ] - 1 >= 0 ) { LU[ 1 ] --; LD[ 1 ] --; }
if( LU[ 0 ] - 1 >= 0 ) { LU[ 0 ] --; RU[ 0 ] --; }
if( RD[ 1 ] + 1 < X ) { RD[ 1 ] ++; RU[ 1 ] ++; }
if( RD[ 0 ] + 1 < Y ) { RD[ 0 ] ++; LD[ 0 ] ++; }
}
/*system( "PAUSE" );*/
}
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

Input:

Code: Select all

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

Code: Select all

``````one.bmp
XX
XX``````
Check input and AC output for thousands of problems on uDebug!