Page 4 of 19

488 - accepted, but PE

Posted: Mon Mar 07, 2005 8:05 pm
by tnaires
Hi everybody,

Here is my code for problem 488:

Code: Select all

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

int main()
{
	int n_cases, *amp, *freq, i, j, k, l;
	
	scanf("%d", &n_cases);
	printf("\n");
	
	amp = (int *) calloc(n_cases, sizeof(int));
	freq = (int *) calloc(n_cases, sizeof(int));
	
	for (i = 0; i < n_cases; i++)
	{
		scanf("%d%d", &amp[i], &freq[i]);
		printf("\n");
	}
	
	for (i = 0; i < n_cases; i++)
	{
		for (j = 0; j < freq[i]; j++)
		{
			for (k = 1; k <= amp[i]; k++)
			{
				for (l = 0; l < k; l++)
					printf("%d", k);
				
				printf("\n");
			}
			
			for (k = amp[i] - 1; k >= 1; k--)
			{
				for (l = 0; l < k; l++)
					printf("%d", k);
				
				printf("\n");
			}
			
			if ((j < freq[i] - 1) || (i < n_cases - 1))
				printf("\n");
		}
	}
	
	free(amp);
	free(freq);
	return 0;
}
It works, but with Presentation Error... Somebody has some suggestion? Thanks a lot, and sorry about my english 8)

Posted: Tue Mar 08, 2005 6:46 am
by shamim
You are first taking all the inputs and then give all the outputs. This is unnecessary and in some problems you will not be able to do so because of the memory contraints..
for (i = 0; i < n_cases; i++)
{
scanf("%d%d", &amp, &freq);
printf("\n");
}


The rason for PE is, as you are taking input, you are printing a newline, which clearly cuases extra newlines to appear in your outpur that are not present in judges output.
I hope this helps.

Posted: Tue Mar 08, 2005 1:37 pm
by tnaires
Hi, shamim. Thanks for attention.
Your tip didn't work... I'm still with a PE. You told me things that left me confused:
shamim wrote:You are first taking all the inputs and then give all the outputs. This is unnecessary and in some problems you will not be able to do so because of the memory contraints..
But in a multiple input problem, I get all the inputs first, then I show the results. Or am I wrong?
shamin wrote:The rason for PE is, as you are taking input, you are printing a newline, which clearly cuases extra newlines to appear in your outpur that are not present in judges output.
But the problem says that "there is also a blank line between two consecutive inputs".
I hope that you can help me. Thanks again, and success for you :D

Posted: Wed Mar 09, 2005 2:11 pm
by tnaires
Hello again.
shamin, I finally understood what you said. I saw the output of the program:

Code: Select all

(blank line)
(blank line)
(blank line)
(blank line)
(blank line)
results
I refreshed my code, using your tips:

Code: Select all

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

int main()
{
	int num_casos, amp, freq, i, j, k, l;
	
	scanf("%d", &num_casos);
	
	for (i = 0; i < num_casos; i++)
	{
		scanf("%d%d", &amp, &freq);
		
		for (j = 0; j < freq; j++)
		{
			for (k = 1; k <= amp; k++)
			{
				for (l = 0; l < k; l++)
				{
					printf("%d", k);
				}
				
				printf("\n");
			}
			
			for (k = amp - 1; k >= 1; k--)
			{
				for (l = 0; l < k; l++)
				{
					printf("%d", k);
				}
				
				printf("\n");
			}
			
			if ((j < freq - 1) || (i < num_casos - 1))
			{
				printf("\n");
			}
		}
	}
	
	return 0;
}
But I'm still having PE!! I'm almost giving up... Does anyone got Accepted in this problem?! :-?
Thanks a lot. 8)

p488

Posted: Mon Mar 14, 2005 4:51 pm
by WR
Print a blank line even after the last output.

input

Code: Select all

2

2
3

3
2
output:

Code: Select all

1
22
1
_
1
22
1
_
1
22
1
_
1
22
333
22
1
_
1
22
333
22
1
_
_ stands for a blank line

Re: p488

Posted: Mon Mar 14, 2005 7:24 pm
by tnaires
WR wrote:Print a blank line even after the last output.
Thanks man! I got AC!!
But I really don't understand it...
The problem says that "There is a blank line after each separate waveform, excluding the last one."
I'd never know of this...

WA 488

Posted: Mon Mar 28, 2005 2:35 pm
by Rony
Hi,
Can any one check my code? I am getting WA continuousely. I think there is something silly mistake.Following is my code.

Code is removed after getting AC. If any one need any help mail me.

Regards
Rony.

Posted: Mon Mar 28, 2005 6:02 pm
by Raj Ariyan
Hi,
This is a multiple input problem right ? And u always print new line after each output. Then what happend with the last output ??? The will be print one extra new line after last output, that should not be happened. So replace by this -->

Must be at the last line,

if(tcase) // last output tcase=0,so false & no newline
puts("");

another is -->

if(f!=1) // When f is 1 in the loop then dont print extra line
puts("");

or u can use it like-->

if(f!=freq) // at the end
puts("");

Second mistake--> U always take input by gets(), but why u need it. There is no character input then sscanf is not necessary. Just replace it by scanf and simply take input. If u use gets then u might get wrong input something like blank line.

Hope it helps.

Re: WA 488

Posted: Tue Mar 29, 2005 9:14 am
by Rony
Hi Raj Ariyan,
I got Ac just replacing ges() and ssanf() function by scanf() function ,nothing else .Not checking also last line \n.
Thanks.

Regards.
Rony
[Depressed]

WA for 488 (Triangle wave)!! can u believe ??pls help me ...

Posted: Wed Mar 30, 2005 8:30 pm
by murkho
<code>

Can u believe I am getting WA for 488(triangle wave)..Yea, it is possible for me. Help me please to find out the reason..Pls..
/*BEGIN_OF_THE_SOURCE_CODE*/

#include<stdio.h>

int main()
{
long int i,j,fre,amp;
long int rep = 0,count=0;
while( scanf("%ld %ld",&amp,&fre)==2)
{
rep=0;
while(rep <fre)
{
if(count !=0)
printf("\n");
for ( i =1;i<=amp;i++)
{
for(j=0;j<i;j++)
printf("%ld",i);
printf("\n");
}

for(i = i-2;i>0;i--)
{
for(j = 0;j<i;j++)
printf("%ld",i);
printf("\n");
}
//printf("\n");
rep++;
count++;
}
}
return 0;
}
/*END_OF_THE_SOURCE_CODE*/
[quote]

Posted: Thu Mar 31, 2005 3:54 pm
by mf
Your code doesn't even work for the sample input given at http://acm.uva.es/p/v4/488.html

I think you missed that it's a multiple-input problem. The first integer gives the number of test cases.

Thanks Mf for your reply

Posted: Thu Mar 31, 2005 7:07 pm
by murkho
Thanks for reply . Actually my problem set with me, nothing said about test case. NOw i got the point. So, thank you.




mf wrote:Your code doesn't even work for the sample input given at http://acm.uva.es/p/v4/488.html

I think you missed that it's a multiple-input problem. The first integer gives the number of test cases.

Plz Help Me On 488.I've got WR

Posted: Sun Jun 05, 2005 7:11 pm
by asif_rahman0
Here is my code.I can't understand why got WR.Plz help me and also give me some inputs and outputs for this problem

#include<stdio.h>

void main()
{
int amp,freq,j,k,l;
while(scanf("%d %d",&amp,&freq)==2)
{

for (j = 0; j < freq; j++)
{
for (k = 1; k <= amp; k++)
{
for (l = 1; l <= k; l++)
{
printf("%d", k);
}

printf("\n");
}

for (k = amp - 1; k >= 1; k--)
{
for (l = 1; l <= k; l++)
{
printf("%d", k);
}

printf("\n");
}


printf("\n");
}
}
}

Posted: Sun Jun 05, 2005 11:19 pm
by Mohammad Mahmudur Rahman
What is WR? :o

Sorry

Posted: Mon Jun 06, 2005 2:54 am
by asif_rahman0
Sorry I've got WA(Wrong Answer).That's my typing mistakes.Rally sorry for that.Plz help me. :(