Page 3 of 4

Posted: Sun Jan 21, 2007 7:33 am
by tgoulart
So the reason of your PE might be a wrong output. For example, if the line that you must print is:

A B _ C D

but you print:

A B C _ D

(change "_" for " ")
it would give you PE! It's just a guess, I can't think about anything else...

Posted: Sun Jan 21, 2007 7:39 am
by stcheung
Thanks for helping. I don't think that could be my mistake. The following is my latest code, which is adapted from yours. board[j] will be ' ' if it's the blank character.

Code: Select all

if(problemnum > 1)
	printf("\n"); 
printf("Puzzle #%d:\n",problemnum);
if(illegal)
    cout << "This puzzle has no final configuration.";
else  {
    for(int i=0; i<5; i++) {
	  printf("%c",board[i][0]); 
      for(int j=1; j<5; j++) {
		printf(" %c",board[i][j]); 
      }
      printf("\n");
    }
}

Posted: Sun Jan 21, 2007 7:43 am
by stcheung
haha after screening my code after posting it, I realize I need the "\n" here:

Code: Select all

cout << "This puzzle has no final configuration.\n";
Thanks again for your help.

Posted: Sun Jan 21, 2007 7:49 am
by tgoulart
I was just going to tell you that! :lol:
I hate when it happens...

Posted: Tue May 08, 2007 3:31 am
by razor_blue
Why WA?? Someone please help me...
Is there any trick here? Let me know... :cry:

Code: Select all

/* Removed after AC */
Thx...

Posted: Tue May 08, 2007 8:26 pm
by Jan
'Z' can appear in the board.

Posted: Thu May 10, 2007 5:11 am
by razor_blue
Thank you...
I didn't realize that... Slight modification give me AC. :D

Posted: Mon Jul 16, 2007 7:28 pm
by chetan
why WA ????? :cry: :cry:

Code: Select all


CODE DELETED 


Posted: Tue Jul 17, 2007 4:49 am
by chetan
please give me some test cases

WA------------> Plz help

Posted: Sat Sep 01, 2007 9:38 pm
by rhsumon
Here is my code ------- What is the wrong i couldn't fine

Code: Select all

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

char mat[10][10],dir[105];
int br,bc;

int valid(int a,int b){
	if(a>=0 && a<5 && b>=0 && b<5)
		return 1;
	return 0;
}

void pos(char ch){
	if(ch == 'A'){
		if(valid(br-1,bc))
			mat[br][bc] = mat[br-1][bc];
		br--;
	}
	else if(ch == 'B'){
		if(valid(br+1,bc))
			mat[br][bc] = mat[br+1][bc];
		br++;
	}
	else if(ch == 'R'){
		if(valid(br,bc+1))
			mat[br][bc] = mat[br][bc+1];
		bc++;
	}
	else if(ch == 'L'){
		if(valid(br,bc-1))
			mat[br][bc] = mat[br][bc-1];
		bc--;
	}
	mat[br][bc] = ' ';
}

int main()
{
	//freopen("227.out","w",stdout);
	int i,j,flag,flg,cas=0,first=1;
	while(gets(mat[0]) != NULL){
		if(strcmp(mat[0],"Z") == 0) break;
		cas++;
		for(i=1; i<5; i++){
			gets(mat[i]);
			for(j=0; j<5; j++){
				if(mat[i][j] == ' '){
					br = i; bc = j;
				}
			}
		}
		while(gets(dir) != NULL){
			flag = flg = 0;
			for(i=0; dir[i]; i++){
				if(dir[i] == '0'){
					flag = 1;
					break;
				}
				pos(dir[i]);
				if(valid(br,bc) == 0){ // If Not valid.......
					flg = 1;
					break;	
				}				
			}
			if(flag == 1 || flg == 1) break;
		}
		if (!first)
			printf("\n");	// Separeted new line......
		printf("Puzzle #%d:\n",cas);
		if(flg == 0){
			for(i=0; i<5; i++){
				for(j=0; j<4; j++)
					printf("%c ",mat[i][j]);
				printf("%c\n",mat[i][j]);
			}
		}
		else printf("This puzzle has no final configuration.\n");
		first = 0;
	}
	return 0;
}

Re: 227 puzzle

Posted: Mon Oct 20, 2008 9:58 am
by porker2008
After reading so many suggestions, I got AC now.

However, I found a very serious problem. The first character of the puzzle might be Z !!!

When you use getchar(), you can't know whether there will be any characters following 'Z'.

I think most of you will search the character and if you found it was 'Z', you quit.

That's why some of you get WA.

For the first line, you should read in all the character together. If there's only a character 'Z', then you can quit.
If the fisrt line is "Z A B C D", you should not quit but read the next line.

P.S. I use getline() to get the character. So I need not to worry about the problem shown above.
However, This will take quite a lot time, because I use string to store the characters.
If somebody have other quicker way, please tell me.

Re: 227 puzzle

Posted: Thu Jan 29, 2009 11:11 am
by MRH
PLZ give me some critical Input-output

Re: 227 puzzle

Posted: Sat Feb 14, 2009 2:57 pm
by calicratis19
it should be assumed that the input which gives the map of moves can have space in them.so a condition for 0 should be added in the code.i got wa 1st time when i didnt.when i did i get ac. :D

Re: 227 puzzle

Posted: Fri May 15, 2009 2:48 pm
by alamgir kabir
I do not find any fault in my code. Anyone can help me to find fault. I am really keen to know my fault.
Please give some special input and output that I get my fault.

Code: Select all

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

int space_i, space_j;
char str [ 1000 ], puzzle [ 6 ][ 6 ];

void find_space()
{
    int i, j;
    for( i = 0; i < 5; i ++ )
    {
        for( j = 0; j < 5; j ++)
        {
            if( puzzle [ i ][ j ] == ' ' )
            {
                space_i = i;
                space_j = j;
            }
        }
    }
    return;
}

void take_pos( int i, int j, int *x, int *y, char c)
{
    if( c == 'A' )
    {
        *x = i - 1;
        *y = j;
    }
    if( c == 'B' )
    {
        *x = i + 1;
        *y = j;
    }
    if( c == 'L' )
    {
        *x = i;
        *y = j - 1;
    }
    if( c == 'R' )
    {
        *x = i;
        *y = j + 1;
    }
    return;
}

bool is_valid_move( int i, int j, char c )
{
    int x, y;
    take_pos(i, j, &x, &y, c);

    if( x >= 0 && x < 5 && y >= 0 && y < 5 )
    {
        puzzle [ i ][ j ] = puzzle [ x ][ y ];
        puzzle [ x ][ y ] = ' ';
        space_i = x;
        space_j = y;
        return true;
    }
    return false;
}

void print_puzzle()
{
    int i, j;
    for( i = 0; i < 5; i ++ )
    {
        for( j = 0; j < 5; j ++ )
        {
            if( j ) printf( " " );
            printf("%c", puzzle [ i ][ j ]);
        }
        printf("\n");
    }
    return;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int i, kase = 1;
    bool final;

    while( gets( str ) )
    {
        if( strcmp(str, "Z") == 0 ) break;
        sscanf(str, "%c %c %c %c %c", &puzzle [ 0 ][ 0 ], &puzzle [ 0 ] [ 1 ], &puzzle [ 0 ] [ 2 ],&puzzle [ 0 ] [ 3 ],&puzzle [ 0 ] [ 4 ]);
        for( i = 1; i < 5; i ++)
        {
            gets( str );
            puzzle [ i ][ 0 ] = str [ 0 ];
            puzzle [ i ] [ 1 ] = str [ 1 ];
            puzzle [ i ] [ 2 ] = str [ 2 ];
            puzzle [ i ] [ 3 ] = str [ 3 ];
            puzzle [ i ] [ 4 ] = str [ 4 ];
        }


        final = true;
        find_space( );


        while( gets( str ) )
        {
            for( i = 0; str [ i ] != '\0' && str [ i ] != '0'; i ++)
            {
                if( final )
                {
                    if( !(str [ i ] == 'A' || str [ i ] == 'B' || str [ i ] == 'R' || str [ i ] == 'L')) final = false;
                    if( final && !is_valid_move(space_i, space_j , str [ i ]) ) final = false;
                }
            }
            if( str [ i ] == '0' ) break;
        }
        if( kase > 1 )printf("\n");
        printf("Puzzle #%d:\n", kase ++);
        if( !final )
        {
            printf("This puzzle has no final configuration.\n");
        }
        else
        {
            print_puzzle();
        }
    }
    return 0;
}
Please help me.
thanks in advance.

Re: 227 puzzle

Posted: Sat Jul 25, 2009 10:13 am
by Jehad Uddin
I got 10 WAs and then got acc, the input is so critical here,change ur input technique and use string class in C++,