445 - Marvelous Mazes

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

Moderator: Board moderators

challenger
New poster
Posts: 6
Joined: Sun Jan 23, 2005 8:21 pm

445 - SIGSEGV

Post by challenger »

Everything works fine... the output is correct...
C:\Valladolid\Debug>445 < aa.txt
T TTTTT
T T TT
T T TT
T T T
TTT T
T T T
TTTTT*T

XX X
XXXX X

C:\Valladolid\Debug>
However I receive an error message:
Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

Before crash, it ran during 0.002 seconds.
I don't understand where the bug is :/

Code: Select all

#include <stdio.h>

main()
{
	char buf[132];
	int n,i,j;

	while( gets(buf)!=NULL )
	{
		if( buf[0]=='\n' )
			printf("\n");
		else
		{
			n=0;
			for(i=0;buf[i]!=0;i++)
				if( buf[i]=='!' )
					putchar('\n');
				else
					if( buf[i]>='1' && buf[i]<='9' )
						n+=buf[i]-48;
					else
					{
						for(j=0;j<n;j++)
							printf("%c",buf[i]=='b' ? 32 : buf[i]);
						n=0;
					}

			putchar('\n');
		}
	}
}
I noticed there is a blank space instead of just '\n'
1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T
<-- space
11X21b1X
4X1b1X
if( buf[0]==32 ) would solve that if we need to look for a blank space instead of '\n'.

Beside that I don't know where the bug might be :/
I need help...

gits
New poster
Posts: 19
Joined: Sun Oct 26, 2003 10:08 pm
Location: Aveiro, Portugal
Contact:

Post by gits »

Problem says no line will be greater than 132 chars, so it can have at most 132 chars, so you must have space for 132 chars plus the ending '\0'.

Try to increase your buf size.

J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

445(marvalues mazes) get W/A Help me please...

Post by J&Jewel »

My out put is correct to me and the program is also...but where is the problem ? I try lot but can`t please help.

Please give me some critical Input and output.Pleaseeeeeeee
I hate Wrong Answer!

challenger
New poster
Posts: 6
Joined: Sun Jan 23, 2005 8:21 pm

Post by challenger »

Like you said I fixed the
char buf[133];


However now I get Accepted (P.E.)
Any idea why is that?
Suggestions to solve it?

Code: Select all

#include <stdio.h> 

main() 
{ 
   char buf[133]; 
   int n,i,j; 

   while( gets(buf)!=NULL ) 
   { 
      if( buf[0]=='\n' ) 
         printf("\n"); 
      else 
      { 
         n=0; 
         for(i=0;buf[i]!=0;i++) 
            if( buf[i]=='!' ) 
               putchar('\n'); 
            else 
               if( buf[i]>='1' && buf[i]<='9' ) 
                  n+=buf[i]-48; 
               else 
               { 
                  for(j=0;j<n;j++) 
                     printf("%c",buf[i]=='b' ? 32 : buf[i]); 
                  n=0; 
               } 

         putchar('\n'); 
      } 
   } 
} 

gits
New poster
Posts: 19
Joined: Sun Oct 26, 2003 10:08 pm
Location: Aveiro, Portugal
Contact:

Post by gits »

Don't write a newline after the last test case.

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

445 WA;[

Post by jaracz »

Hi!
Could enyone tell me how can I recognise the blank line from the input file??

regards
keep it real!

ahmed hasan
New poster
Posts: 9
Joined: Fri Jan 21, 2005 5:09 pm

Re: 445 WA;[

Post by ahmed hasan »

for c use gets(string) to get input.
if strlen(string)==0 than the input is a blank line;
for c++ use geline(cin,string)
if string.length()==0 than input is a blank line

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

well..
it works now :D

thanks!!
keep it real!

mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince »

Hi
u can send me ur code

MAP

JackBauer
New poster
Posts: 19
Joined: Sun Mar 21, 2004 8:07 pm

Post by JackBauer »

After trying a few ways my program still gets PE.

Tried with \n after the last output, PE.
Tried without \n after the last out, PE.

Does anyone have some crazy input to test this to see if proper formating fails in some case?

Thanks.

challenger
New poster
Posts: 6
Joined: Sun Jan 23, 2005 8:21 pm

Still Accepted (P.E.)

Post by challenger »

I fixed the newline thing, placed a flag to check the first execution.. it looks right to me. Don't know why it keeps PE :/
C:\Valladolid\challenges\Debug>445_WA_PE.exe < 445.txt
T TTTTT
T T TT
T T TT
T T T
TTT T
T T T
TTTTT*T

XX X
XXXX X
C:\Valladolid\challenges\Debug>

Code: Select all

/* Marvelous Mazes */
#include <stdio.h>

main()
{
	char buf[133];
	int n,i,j,flag=0;

	while( gets(buf)!=NULL)
	{
		if (flag == 0)
			flag = 1;
		else
			putchar('\n');

		/* Check if a blank line is read */
		if( buf[0]=='\n' )
			putchar('\n');
		else
		{
			/* Draw the maze */
			n=0;
			for(i=0;buf[i]!=0;i++)

				if( buf[i]=='!' )
					putchar('\n');
				else
					if( buf[i]>='1' && buf[i]<='9' )
						n+=buf[i]-48;
					else
					{
						for(j=0;j<n;j++)
							printf("%c",buf[i]=='b' ? 32 : buf[i]);
						n=0;
					}
		}
	}
}
Any help is wellcome :|


PS: I am from Portugal too :)

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

PE - 445 - Marveleous Mazes

Post by Roby »

Oh my God, why I always got PE for this problem!
Can somebody helps me to find what's wrong with my code below:

Code: Select all

CUT !!!
My output is right, isn't it?
Last edited by Roby on Wed Nov 23, 2005 1:09 pm, edited 1 time in total.

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

Post by Roby »

I revised my code, here's:

Code: Select all

CUT !!!
And I still have PE on it. Help me please........ :oops:
Last edited by Roby on Wed Nov 23, 2005 1:17 pm, edited 1 time in total.

Trust Noone
New poster
Posts: 4
Joined: Wed Nov 16, 2005 8:54 pm

Post by Trust Noone »

Try with this input:
1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T!

11X21b1X!
4X1b1X!

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

Post by Roby »

Thanx for the reply... My program gave output like this:

Code: Select all

T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T


XX   X

XXXX X

Are those wrong? Or it should be like this:

Code: Select all

T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T

XX   X
XXXX X


Post Reply

Return to “Volume 4 (400-499)”