## 488 - Triangle Wave

Moderator: Board moderators

davidbuzatto
New poster
Posts: 1
Joined: Wed Dec 28, 2011 4:47 pm

### Re: 488 - PRESENTATION ERROR!

Hello everybody,

I getting a WA, but I really don't understand why.

My input:

Code: Select all

``````6

3
2

1
0

1
1

2
2

1
0

3
3``````
My output:

Code: Select all

``````1
22
333
22
1

1
22
333
22
1

1

1
22
1

1
22
1

1
22
333
22
1

1
22
333
22
1

1
22
333
22
1 (no \n)``````
Thank you very much!

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

### Re: 488

I tested your code and only got a blank line and then an infinite loop for the sample input. I used scanf to solve this problem.

Check input and AC output for thousands of problems on uDebug!

avinashse
New poster
Posts: 2
Joined: Mon Feb 20, 2012 11:36 am

### 488 - Triangle Wave

Hello Sir, I am continuosly getting wrong answer in my code, I am bit confused with the scene where to give new line and where not, but i think i have fulfilled all the criteria, but still getting WA, don't know what to do and where to correct.
Here is my code :-

Code: Select all

``````Removed after AC :)
``````
Last edited by avinashse on Sun Feb 26, 2012 11:17 am, edited 2 times in total.

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

wz0o0zw
New poster
Posts: 3
Joined: Mon Mar 19, 2012 5:33 pm

### WA 488 help plz

i got WA,and my output is the same as the answer, i submit many times, but it always WA!!
this is my code:

#include <iostream>
#define MAXAMP 9
using namespace std;
int main()
{
int n,Amp,Fre,elem,k,l=0,m=0;
while(cin>>n)
while(n--)
{
cin>>Amp>>Fre;
if(Amp>MAXAMP||Amp<=0)
break;
//if(l=0;
if(n!=0)
m=Fre;
else
m=Fre-1;
for(int i=0;i<Fre;i++)
{
for(int j=1;j<=Amp;j++)
{
k=elem=j;
if(l!=0)
cout<<'\n';
l=1;
while(k--)
cout<<elem;
}
for(int j=Amp-1;j>=1;j--)
{
k=elem=j;
if(l!=0)
cout<<'\n';
while(k--)
cout<<elem;
}
if(m--)
cout<<'\n';
}
}
return 0;
}

plz help me,Thanks!

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

### Re: WA 488 help plz

Missing newline at end of output.
Check input and AC output for thousands of problems on uDebug!

xtine.m
New poster
Posts: 6
Joined: Tue May 08, 2012 5:36 pm

### 488 Time Limit Exceeded

Hi! I always got TLE. Can anybody tell me what's making it slow? Here's my code:

#include <stdio.h>

int main() {
int amp;
int freq;
int Tamp;
int a;
int b;
int c;
int d = 1;
int e = 0;
int temp;

while (scanf("%d",&amp) != EOF) {
scanf("%d",&freq);
Tamp = (amp * 2) - 1;
for (a = freq;a > 0;a--) {
d = 1;
e = 0;
for (b = Tamp;b > 0;b--) {
for (c = d;c > 0;c--){
printf("%d",d);
}
if (d == amp) {
e = d;
}

if (e > 0){
d--;
} else {
d++;
}
printf("\n");
}
if (a != 1) {
printf("\n");
}
}
printf("\n");
}
return 0;
}

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

### Re: 488 Time Limit Exceeded

Your problem is the way you read the input. Your code doesn't work for the sample I/O.
The input begins with a single positive integer on a line by itself indicating the number of the cases following.
Check input and AC output for thousands of problems on uDebug!

sonjbond
New poster
Posts: 19
Joined: Wed Jul 04, 2012 10:30 pm

### Re: 488

um also getting WA ,,, in this problem ,,, .. here's my code

code removed
Last edited by sonjbond on Thu Jul 05, 2012 9:10 pm, edited 1 time in total.

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

### Re: 488

Don't print an extra newline at the end of the output.
Check input and AC output for thousands of problems on uDebug!

sonjbond
New poster
Posts: 19
Joined: Wed Jul 04, 2012 10:30 pm

### Re: 488

brianfry713 wrote:Don't print an extra newline at the end of the output.
thanx,,, now i get AC

wangluofan
New poster
Posts: 6
Joined: Tue Aug 07, 2012 7:00 pm

### 488-Triangle Wave

Code: Select all

``````#include<stdio.h>

int Output(int Amplitude)
{
int index;
for(index=1;index<=Amplitude;++index)
{
for(int j=0;j!=index;++j)
printf("%d",index);
printf("\n");
}
for(index=index-2;index!=0;--index)
{
for(int j=0;j!=index;++j)
printf("%d",index);
printf("\n");
}
return 0;
}
int main(void)
{
int Case,Amplitude,Frequency;
scanf("%d",&Case);
while(Case--)
{
//scanf("%d%d",&Amplitude,&Frequency);
scanf("%d%d",&Amplitude,&Frequency);
for(int j=1;j<=Frequency;j++)
{
Output(Amplitude);
if(Case!=0||j!=Frequency)
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

That is AC code.
Check input and AC output for thousands of problems on uDebug!

wangluofan
New poster
Posts: 6
Joined: Tue Aug 07, 2012 7:00 pm

### Re: 488-Triangle Wave

Really?I'm think so too.But I really got a WA?

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

### Re: 488-Triangle Wave

Submit it again.
Check input and AC output for thousands of problems on uDebug!