488 - Triangle Wave

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

Post Reply
Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman »

You're program doesn't handle multiple test cases. Note that, the first line of the input file will contain the number of test cases. It was not specified in older versions of the problemset. So, if you use previously downloaded problemset, make sure to update it.
You should never take more than you give in the circle of life.

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

488 PE

Post by Roby »

Can somebody help to me find what's wrong with my codes below:

Code: Select all

#include <stdio.h>

int main()
{
 int ampl = 0, freq = 0, n = 0;
 int i = 0, j = 0, k = 0, a = 0, b = 0;
 
 scanf( "%d\n\n", &n );
 
 for ( b = 0; b < n; b++ )
 {
    scanf( "%d %d\n\n", &ampl, &freq );
    
    if ( b )
       printf("\n");
    
    for ( i = 0; i < freq; i++ )
    {
       if ( i )
          printf("\n");
       
       for ( j = 1, a = 1; j > 0; j += a )
       {
          for ( k = 0; k < j; k++ )
             printf("%d", j);
          
          a = ( j == ampl ) ? -1 : a;
          
          if ( a < 0 && j == 1 && i == freq - 1 && b == n - 1 );
          else printf("\n");
       }
    }
 }
 
 return 0;
}
Here's the input of my program:

Code: Select all

3

3 2

7 9

9 20
and here's the output of my program:

Code: Select all

1
22
333
22
1

1
22
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1
Is my algorithm right?

InfiniteLOOP
New poster
Posts: 2
Joined: Mon Oct 10, 2005 6:52 pm
Location: Dhaka,Bangladesh

488 Tangle in triangle wave

Post by InfiniteLOOP »

Not Getting ac, where's the problem?


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>

int i=0,j=0,k=0,l=0,c=0,a=0,wf=0;

void main()
{
while (scanf("%d",&c)!=EOF)
{
for (l=1;l<=c;l++){
scanf("%d %d",&a,&wf);
for (k=1;k<=wf;k++)
{
for (i=1;i<=a;i++)
{
for (j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}

for (i=a-1;i>=1;i--)
{
for (j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
}
}
}
Programming is LIFE!!
LIFE is programming!!

smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude »

Oh dear....
why dont you use indentation??
hmm... its a multiple input problem... if you look back some page there is another thread on 488!
fahim
#include <smile.h>

smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude »

i didnt tell you, they have changed the input specification.
there is a line like

<number of inputs>
....<inputs>.....
....<inputs>.....

i stucked on this prob for half a year. I didnt know, they have change the format and the problemset i had was too old for that change
fahim
#include <smile.h>

lastlaugh
New poster
Posts: 1
Joined: Tue Dec 06, 2005 5:29 pm

488

Post by lastlaugh »

This is my code, but the status is "Presentation Error".

I have checked it many times, but i still can not understand what mistakes I make.

Could you hlep me?
Thanks very much.

#include <stdio.h>

void outPutALine(int outputNumber)
{
for(int i=0;i<outputNumber;i++)
printf("%d",outputNumber);
printf("\n");
}

void outputASet(int mediumValue,int howManyShouldDo)
{
for(int j=0;j<howManyShouldDo;j++)
{
for(int i=1;i<=(2*mediumValue-1);i++)
{
if(i<=mediumValue)
outPutALine(i);
else
outPutALine(2*mediumValue-i);
}
printf("\n");
}
}

int main()
{
int counter,mediumValue,howManyShouldDo;
scanf("%d",&counter);
for(int i=0;i<counter;i++)
{
scanf(" %d %d",&mediumValue,&howManyShouldDo);
printf("\n");
outputASet(mediumValue,howManyShouldDo);
}
return 0;
}

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

Post by Trust Noone »

I think you must delete printf("\n"); in main()

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel »

Guess what? WA :-?
I've read all the threads concerning this problem and tried many things and still nothing.

Code: Select all

code AC
What am I missing?
Some inputs/outputs would help to clarify :?
Thanks.
Last edited by Schutzstaffel on Mon Jan 09, 2006 2:57 pm, edited 1 time in total.
Image

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman »

I think the way you're handling the newline charecters, there won't be one at the end of the last line of the last test case. This will lead to WA.
You should never take more than you give in the circle of life.

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel »

But I don't have a newline after the last test case, that's the weird part :-?

Input

Code: Select all

3

3
2

5
3

6
4

1

3
2

Code: Select all

1
22
333
22
1

1
22
333
22
1

1
22
333
4444
55555
4444
333
22
1

1
22
333
4444
55555
4444
333
22
1

1
22
333
4444
55555
4444
333
22
1

1
22
333
4444
55555
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
55555
4444
333
22
1

1
22
333
4444
55555
666666
55555
4444
333
22
1

1
22
333
22
1

1
22
333
22
1 /* ends here*/
Is this a valid output?
Thanks for your help.
Image

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Your sample input is not correct.

The input format given in the problem is

<number of test cases>

<input data>

Running your code with a test case and comparing the output with my just ACed code shows that your output does not have a newline at the end as Mohammad Rahman has pointed out.

You should print each line of output with a newline at the end.

However, the judge's test cases does not seem to agree with the sample output format which says that there is no newline after the output of the last test case.
NOTE: There is a blank line after each separate waveform, excluding the last one.
I got a PE without printing newline after the last test case and AC after printing a newline after every triangle wave.

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel »

I'm not sure if I understand what you're saying, I tried to print a newline after each wave including the last one and got WA, then tried without it as I thought it was supposed to be and got also WA

Code: Select all

code AC
If you have

Code: Select all

1

3
3
Should the output be:

Code: Select all

1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1
Or should it be:

Code: Select all

1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1\n
Thanks for your help.
Last edited by Schutzstaffel on Mon Jan 09, 2006 2:57 pm, edited 1 time in total.
Image

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

The second one

Try this test case:

Input:

Code: Select all

3

3
2

4
3

5
4
Correct output should be:

Code: Select all

1
22
333
22
1

1
22
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
55555
4444
333
22
1

1
22
333
4444
55555
4444
333
22
1

1
22
333
4444
55555
4444
333
22
1

1
22
333
4444
55555
4444
333
22
1

Your code is now printing extra blank lines.

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel »

Thanks, I corrected the extra blank line but it still gives WA. Maybe it miss some critical case :o I've tried every possible way (I think) for the newlines.

Code: Select all

code AC
The output for the input you gave is the same as yours but I also tried to make the last line without the \n because I wasn't sure if it had a newline or not but the results were the same.
I really appreciate your help, thanks.
Last edited by Schutzstaffel on Mon Jan 09, 2006 2:58 pm, edited 1 time in total.
Image

Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

Post by Emilio »

To Schutzstaffel:

This is your modified code, give AC.
Reply when you see this post and I will cut off here.

Code: Select all

CUT
Last edited by Emilio on Tue Jan 10, 2006 6:00 pm, edited 2 times in total.

Post Reply

Return to “Volume 4 (400-499)”