488 - Triangle Wave
Moderator: Board moderators
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
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.
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
488 PE
Can somebody help to me find what's wrong with my codes below:
Here's the input of my program:
and here's the output of my program:
Is my algorithm right?
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", &l, &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;
}
Code: Select all
3
3 2
7 9
9 20
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
-
- New poster
- Posts: 2
- Joined: Mon Oct 10, 2005 6:52 pm
- Location: Dhaka,Bangladesh
488 Tangle in triangle wave
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");
}
}
}
}
}
#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!!
LIFE is programming!!
488
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;
}
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;
}
-
- New poster
- Posts: 4
- Joined: Wed Nov 16, 2005 8:54 pm
-
- New poster
- Posts: 37
- Joined: Fri Apr 30, 2004 6:52 pm
- Location: Portugal
Guess what? WA
I've read all the threads concerning this problem and tried many things and still nothing.
What am I missing?
Some inputs/outputs would help to clarify :?
Thanks.

I've read all the threads concerning this problem and tried many things and still nothing.
Code: Select all
code AC
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.
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- New poster
- Posts: 37
- Joined: Fri Apr 30, 2004 6:52 pm
- Location: Portugal
But I don't have a newline after the last test case, that's the weird part
Input
Is this a valid output?
Thanks for your help.

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*/
Thanks for your help.
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.
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.
I got a PE without printing newline after the last test case and AC after printing a newline after every triangle wave.NOTE: There is a blank line after each separate waveform, excluding the last one.
-
- New poster
- Posts: 37
- Joined: Fri Apr 30, 2004 6:52 pm
- Location: Portugal
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
If you have
Should the output be:
Or should it be:
Thanks for your help.
Code: Select all
code AC
Code: Select all
1
3
3
Code: Select all
1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1
Code: Select all
1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1\n
Last edited by Schutzstaffel on Mon Jan 09, 2006 2:57 pm, edited 1 time in total.
The second one
Try this test case:
Input:
Correct output should be:
Your code is now printing extra blank lines.
Try this test case:
Input:
Code: Select all
3
3
2
4
3
5
4
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
-
- New poster
- Posts: 37
- Joined: Fri Apr 30, 2004 6:52 pm
- Location: Portugal
Thanks, I corrected the extra blank line but it still gives WA. Maybe it miss some critical case
I've tried every possible way (I think) for the newlines.
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.

Code: Select all
code AC
I really appreciate your help, thanks.
Last edited by Schutzstaffel on Mon Jan 09, 2006 2:58 pm, edited 1 time in total.
To Schutzstaffel:
This is your modified code, give AC.
Reply when you see this post and I will cut off here.
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.