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

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

Re: 488 - PRESENTATION ERROR!

Post by davidbuzatto » Wed Dec 28, 2011 4:50 pm

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

Post by brianfry713 » Fri Jan 06, 2012 11:55 pm

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.

Post your questions to an existing thread about a problem. Use the code block for better readability.
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

Post by avinashse » Tue Feb 21, 2012 6:22 pm

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.
Please help me sir. :oops:
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

Post by brianfry713 » Wed Feb 22, 2012 8:06 pm

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

Post by wz0o0zw » Tue Mar 20, 2012 4:55 pm

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

Post by brianfry713 » Tue Mar 20, 2012 9:41 pm

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

Post by xtine.m » Tue May 08, 2012 5:44 pm

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

Post by brianfry713 » Wed May 09, 2012 3:47 am

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

Post by sonjbond » Wed Jul 04, 2012 10:46 pm

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

Post by brianfry713 » Thu Jul 05, 2012 3:49 am

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

Post by sonjbond » Thu Jul 05, 2012 9:08 pm

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

Post by wangluofan » Mon Aug 13, 2012 7:12 pm

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;
}
Why this code Wrong?Please help me,Thank you!

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

Re: 488-Triangle Wave

Post by brianfry713 » Mon Aug 13, 2012 11:40 pm

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

Post by wangluofan » Tue Aug 14, 2012 3:57 am

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

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

Re: 488-Triangle Wave

Post by brianfry713 » Tue Aug 14, 2012 11:03 pm

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

Post Reply

Return to “Volume 4 (400-499)”