## 488 - Triangle Wave

Moderator: Board moderators

Dendesha
New poster
Posts: 1
Joined: Thu Jan 31, 2013 8:55 pm

### Re: 488 - Triangle Wave

I don't know why am I getting wrong answer can any one help?

Code: Select all

``````#include<stdio.h>
int main()
{
int t,n,f;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&f);
for(int l=0;l<f;l++)
{
for(int j=1;j<=n;j++)
{
for(int k=0;k<j;k++)
{
printf("%d",j);
}
printf("\n");
}
for(int m=n-1;m>0;m--)
{
for(int h=0;h<m;h++)
{
printf("%d",m);
}
printf("\n");
}
if(l<f-1)
{
printf("\n");
}

}

}
return 0;
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 - Triangle Wave

Input:

Code: Select all

``````2

3
2

4
1``````
AC output:

Code: Select all

``````1
22
333
22
1

1
22
333
22
1

1
22
333
4444
333
22
1
``````
Check input and AC output for thousands of problems on uDebug!

omarking06
New poster
Posts: 6
Joined: Fri Mar 15, 2013 1:07 am

### Re: 488 - PRESENTATION ERROR!

Whats wrong with this code please !!! .. i checked the I/O !! and nothing !!
I got WA!

Code: Select all

``````#include <iostream>
using namespace std;

int main()
{
int t,a,f;
cin>>t;
for (int i=0;i<t;i++)
{
cin>>a>>f;
for (int i=0;i<f;i++)
{
for (int j=1;j<=a;j++)
{
cout<<j;
for (int k=1;k<j;k++)
{
cout<<j;
}
cout<<endl;
}

for (int x=a-1;x>0;x--)
{
cout<<x;
for (int y=x;y>1;y--)
{
cout<<x;
}
cout<<endl;
}
if (i==f-1) continue;
cout<<endl;
}
}
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 - PRESENTATION ERROR!

Input:

Code: Select all

``````2

3
2

4
3``````
Correct output:

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
``````
Check input and AC output for thousands of problems on uDebug!

omarking06
New poster
Posts: 6
Joined: Fri Mar 15, 2013 1:07 am

### Re: 488 - PRESENTATION ERROR!

here is my I/O :

Code: Select all

``````2
3
2
1
22
333
22
1

1
22
333
22
1
4
3
1
22
333
4444
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1``````
i dont see anything wrong !!

omarking06
New poster
Posts: 6
Joined: Fri Mar 15, 2013 1:07 am

### Re: 488 - PRESENTATION ERROR!

Plz Help !

omarking06
New poster
Posts: 6
Joined: Fri Mar 15, 2013 1:07 am

### 488 - Triangle Wave

I really dont know whats wrong with my code !?
I got WA!!!

Code: Select all

``````    #include <iostream>
using namespace std;

int main()
{
int t,a,f;
cin>>t;
for (int i=0;i<t;i++)
{
cin>>a>>f;
for (int i=0;i<f;i++)
{
for (int j=1;j<=a;j++)
{
cout<<j;
for (int k=1;k<j;k++)
{
cout<<j;
}
cout<<endl;
}

for (int x=a-1;x>0;x--)
{
cout<<x;
for (int y=x;y>1;y--)
{
cout<<x;
}
cout<<endl;
}
if (i==f-1) continue;
cout<<endl;
}
}
}``````
and here is my I/O :

Code: Select all

``````    2
3
2
1
22
333
22
1

1
22
333
22
1
4
3
1
22
333
4444
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 - PRESENTATION ERROR!

See:
http://ideone.com/bOWwDv

For input:

Code: Select all

``````2

3
2

4
3``````
The correct output is:

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``````

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``````
As you can see, there is a blank line missing.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 - Triangle Wave

Don't double post.
Check input and AC output for thousands of problems on uDebug!

mfjuzar
New poster
Posts: 3
Joined: Thu Mar 28, 2013 6:37 am

### 488 - Triangle Wave WA?

Why did I keep getting WA? The program input and output is exactly the same as the problem example,
I'm browsing the forum for my problems but it seems that I already get my code right, I've checked the blank lines needed too, but still

Code: Select all

``````var
c,i,k,wave,cases,amp,ampd,j: integer;
a,f:array [1..10000] of integer;

begin
writeln;

for k:=1 to c do begin
if k=c then else writeln;
end;

for cases:= 1 to c do begin
for wave:= 1 to f[cases] do begin
for amp:= 1 to a[cases] do begin
for i:= 1 to amp do begin
write (amp);
end;
writeln;
end;
for ampd:= amp-1 downto 1 do begin
for j:= ampd downto 1 do begin
write (ampd);
end;
writeln;
end;
if wave=f[cases] then else writeln;
end;
if cases=c then else writeln;
end;
end.

``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 - Triangle Wave WA?

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!

mfjuzar
New poster
Posts: 3
Joined: Thu Mar 28, 2013 6:37 am

### Re: 488 - Triangle Wave WA?

brianfry713 wrote:Don't print a blank line at the start of the output.
It doesn't print any

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 - Triangle Wave WA?

Why is line 7 of your code writeln;?
Check input and AC output for thousands of problems on uDebug!

safait
New poster
Posts: 4
Joined: Sat Jun 08, 2013 10:49 am

### 488 WA

what is the in my code:

Code: Select all

``````#include<stdio.h>
int main()
{

int a,f,i,j,x,t;
scanf("%d",&t);
i=t-1;
while(t-->0)
{
scanf("%d%d",&a,&f);
if(t<i)
printf("\n");
for(i=0;i<f;i++){
for(j=1;j<=a;j++){
for(x=0;x<j;x++)
printf("%d",j);
printf("\n");
}
j-=2;
for(;j>=1;j--){
for(x=0;x<j;x++)
printf("%d",j);
printf("\n");
}
if(i<f-1)
printf("\n");
}
}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 488 WA

Input:

Code: Select all

``````3

3
1

4
3

4
3
``````
AC output:

Code: Select all

``````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
333
22
1

1
22
333
4444
333
22
1

1
22
333
4444
333
22
1
``````
You are reusing i in your code that is causing the blank line not to be printed in this case.
Last edited by brianfry713 on Thu Nov 21, 2013 8:35 pm, edited 1 time in total.
Check input and AC output for thousands of problems on uDebug!