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

dewsworld
New poster
Posts: 12
Joined: Fri Aug 13, 2010 11:52 am

Re: 488 - Triangle Wave

Post by dewsworld » Sat Nov 27, 2010 6:03 pm

Could anyone help me with this code please? I can't shoot the problem.

Code: Select all

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

int main()
{
//    freopen("in.txt", "r", stdin ) ;

    int noTest ;
    int a, f ;
    int i, j, k ;

    cin >> noTest ;
    while( noTest-- )
    {
        cin >> a >> f ;

        for( i = 0 ; i < f ; i++ )
        {
            for( j = 1 ; j <= a ; j++ )
            {
                for( k = 0 ; k < j ; k++ )
                    cout << j ;
                cout << endl ;
            }
            for( j = a-1 ; j > 0 ; j-- )
            {
                for( k = 0 ; k < j ; k++ )
                    cout << j ;
                if( noTest != 0 || i != f-1 || j != 1)  cout << endl ;
            }
            if( noTest != 0 || i != f-1 )   cout << endl ;
        }
    }

    return 0 ;
}

dewsworld
New poster
Posts: 12
Joined: Fri Aug 13, 2010 11:52 am

Re: WA 488

Post by dewsworld » Sun Nov 28, 2010 10:36 am

Well I recode it and there is no newline problem I guess,
Still I'm getting WA

Code: Select all

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

int main()
{
//    freopen("in.txt", "r", stdin ) ;

    int noTest ;
    int a, f ;
    int i, j, k ;

    cin >> noTest ;
    while( noTest-- )
    {
        cin >> a >> f ;

        for( i = 0 ; i < f ; i++ )
        {
            for( j = 1 ; j <= a ; j++ )
            {
                for( k = 0 ; k < j ; k++ )
                    cout << j ;
                cout << endl ;
            }
            for( j = a-1 ; j > 0 ; j-- )
            {
                for( k = 0 ; k < j ; k++ )
                    cout << j ;
                if( noTest != 0 || i != f-1 || j != 1)  cout << endl ;
            }
            if( noTest != 0 || i != f-1 )   cout << endl ;
        }
    }

    return 0 ;
}

asif_iut
New poster
Posts: 16
Joined: Mon Nov 01, 2010 8:08 am

Re: WA 488

Post by asif_iut » Thu Dec 09, 2010 8:46 pm

I think there should be a newline after the very last test case( not a blank line )

dream
New poster
Posts: 3
Joined: Sat Feb 19, 2011 4:40 pm

488 WA WA WA.. :(

Post by dream » Sun Feb 20, 2011 9:20 pm

can anybody help me ??
where is the problem ??
i got wrong answer :( :(
#include<stdio.h>
int main()
{
int wave,amp,n;
scanf("%d",&n);
for(int b=1;b<=n;b++)
{
scanf("%d%d",&amp,&wave);
for(int a=1;a<=wave;a++)
{
for(int i=1;i<=amp;i++)
{
for(int k=1;k<=i;k++)
{
printf("%d",i);
}
printf("\n");
}
for(int i=amp-1;i>0;i--)
{
for(int k=i;k>0;k--)
{
printf("%d",i);
}
printf("\n");
}
if(a<wave)
printf("\n");
}
}
return 0;
}

lprell
New poster
Posts: 5
Joined: Fri Jun 17, 2011 8:56 am

Re: 488 WA WA WA.. :(

Post by lprell » Fri Jun 17, 2011 9:55 am

Guys, im new into programming and im new to the UVA.
I have some issues on this problem. Always getting WA.
I appreciate some help. Thanks in advance.
My code is below:
Got AC. The problem was the last blank line. :)

cbminm
New poster
Posts: 1
Joined: Wed Jun 29, 2011 8:39 am

488

Post by cbminm » Wed Jun 29, 2011 9:33 am

:oops: Where is the problem of this code?

#include<iostream.h>

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

for(j=a-1;j>0;j--)
{
for(k=j;k>=1;k--)
cout<<j;
cout<<endl;
}
}

if(!t&&i<f) cout<<endl;
}
return 0;
}

Scarecrow
Learning poster
Posts: 69
Joined: Wed Oct 19, 2011 9:06 pm

488 Triangle Wave

Post by Scarecrow » Wed Oct 19, 2011 9:16 pm

why i'm getting WA? can sm1 help me.. :(

#include<stdio.h>
int main()
{
int test,a,f;register int i,j,k,l;
scanf("%d",&test);
printf("\n");
for(i=1;i<=test;i++)
{
scanf("%d",&a);
scanf("%d",&f);
if(!i)
printf("\n");
for(l=1;l<=f;l++)
{
for(j=1;j<=a;j++)
{
for(k=1;k<=j;k++)
printf("%d",j);
printf("\n");
}
for(j=a-1;j>=1;j--)
{
for(k=1;k<=j;k++)
printf("%d",j);
printf("\n");
}
if(!(i==test && l==f))
printf("\n");
}
}
return 0;
}

Code: Select all

[code]
[/code]
Do or do not. There is no try.

Scarecrow
Learning poster
Posts: 69
Joined: Wed Oct 19, 2011 9:06 pm

Re: 488 Triangle Wave

Post by Scarecrow » Mon Oct 31, 2011 3:52 pm

sry..the code is -

Code: Select all

got AC
Do or do not. There is no try.

tzupengwang
New poster
Posts: 36
Joined: Fri Dec 02, 2011 1:30 pm
Location: Kaohsiung, Taiwan

488-Triangle Wave -why WA?

Post by tzupengwang » Fri Dec 02, 2011 2:20 pm

I do not know why i got WA
the program went well when i tested it.
could anyone help me?

Code: Select all

/*488*/
#include<stdio.h>
int main()
{
	int a;
	while(scanf("%d",&a)==1)
	   {
		int i;		
		for(i=1;i<=a;i++)
		   {
			int p,q;	
			scanf("%d%d",&p,&q);	
			int time;
			for(time=1;time<=q;time++)
			    {
				 int k;	
				 for(k=1;k<=p;k++)	
					{
					 int w;
					 for(w=1;w<=k;w++)printf("%d",k);	
					 puts("");	
					}
				 for(k=p-1;k>0;k--)
				    {
					 int w;
					 for(w=1;w<=k;w++)printf("%d",k);
					 puts(""); 	
					}	
				 puts("");	
				}	
		   }	
	   }	
return 0;	
}
 

tzupengwang
New poster
Posts: 36
Joined: Fri Dec 02, 2011 1:30 pm
Location: Kaohsiung, Taiwan

Re: 488-Triangle Wave -why WA?

Post by tzupengwang » Sat Dec 03, 2011 4:59 am

is anyone willing to help?
Thanks :D

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 488-Triangle Wave -why WA?

Post by helloneo » Sat Dec 03, 2011 6:02 am

See this thread

http://acm.uva.es/board/viewtopic.php?f=5&t=10991

Remove your code if you get AC :)

tzupengwang
New poster
Posts: 36
Joined: Fri Dec 02, 2011 1:30 pm
Location: Kaohsiung, Taiwan

Re: 488-Triangle Wave -why WA?

Post by tzupengwang » Sat Dec 03, 2011 7:34 am

thanks for your help,but i still don't get it
i think it's the blank problem that led to WA,just as discussed in the thread you offered
could you make a further explanation?
THANKS~

artless
New poster
Posts: 7
Joined: Tue Nov 22, 2011 2:01 pm

why i am getting WA?(for 488)

Post by artless » Sat Dec 03, 2011 7:25 pm

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

if(m!=t)
printf("\n");
}
}
}
return 0;
}

leobonalume
New poster
Posts: 5
Joined: Mon May 09, 2011 8:49 pm

Re: 488-Triangle Wave -why WA?

Post by leobonalume » Fri Dec 09, 2011 9:41 pm

tzupengwang wrote:thanks for your help,but i still don't get it
i think it's the blank problem that led to WA,just as discussed in the thread you offered
could you make a further explanation?
THANKS~
Hi, i'll try to help.
Taken from problem description: "NOTE: There is a blank line after each separate waveform, excluding the last one.".
What's happening in your program is that you are printing a blank line after the last waveform, like this:

Code: Select all

1
22
333
22
1
BLANK LINE
1
22
333
22
1
BLANK LINE
And the correct output should be like this:

Code: Select all

1
22
333
22
1
BLANK LINE
1
22
333
22
1

abyraneses
New poster
Posts: 1
Joined: Sun Dec 18, 2011 9:03 am

488

Post by abyraneses » Sun Dec 18, 2011 10:34 am

#include <iostream>

using namespace std;

int main(){

int cASE, amplitude, frequency;


cout << "";
cin >> cASE;
cout << endl;
int a[cASE-1];
int f[cASE-1];

int i = 0;
do{
do{
cout << "";
cin >> a;
}
while (a < 9);
cout << "";
cin >> f;
i++;
}
while (i < cASE);


for (int j = 0; j < cASE; j++){ // checking of base case
for (int k = 1; k <= f[j]; k++){ // checking of frequency every case
for (int l = 1; l <= a[j]; l++){ // checking of amplitude for every case
for (int m = 1; m <= l; m ++){ // how many same numbers will be printed each line
cout << l; // printing
}
cout << endl;
}

for (int n = a[j]; n >= 1; n--){ // starts after half of the amplitude
for (int o = 1; o <= n-1; o++){ // how many same numbers will be printed each line
cout << n-1; // printing
}
if (n-1>1)
cout << endl;
}

cout << endl;
if (k < f[j])
cout << endl;

}

}

return 0;
}


what's wrong with my code??
i need some help..please..

Post Reply

Return to “Volume 4 (400-499)”