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

brrs
New poster
Posts: 1
Joined: Thu Sep 17, 2009 9:42 pm

Re: WA 488

Post by brrs »

Hello guys, it is my first post here and 488 is the first problem I trying to solve
So, i have tryed a lot of changes, but I am always geting WA
Can anybody help me to find what is wrong in my code? Please?

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, amp, freq, i, j, k, l;
    
    scanf("%d", &n);
    while(n > 0) {        
        scanf("%d %d", &amp, &freq);
        for(i = 1; i <= freq; i++) {
            for(j = 1; j <= amp; j++) {
                for(k = 0; k < j; k++) {
                    printf("%d", j);
                }
                printf("\n");
            }
            for(k = amp - 1; k > 0; k--) {
                for(l = 0; l < k; l++) {
                    printf("%d", k);
                }
                if(k > 1) {
                    printf("\n");    
                }
            }
            if(i < freq) {
                printf("\n\n");    
            }
        }
        if(n != 1) printf("\n\n");
        n--;
    }
    system("pause"); /*uncomment it before sending*/
    return 0;
}
Thank you all

sushant1
New poster
Posts: 1
Joined: Tue Sep 29, 2009 8:13 pm

488 triangle wave (wrong answer)

Post by sushant1 »

my code...
#include<iostream.h>
void wave(long long a,long long f)
{
long long i,k,j,l;
for(l=0;l<f;l++)
{
for(j=1;j<(2*a);j++)
{
k=j;
if(j>a)
k=(a-(j-a));
for(i=0;i<k;i++)
cout<<k;
cout<<endl;
}
if(l<f-1)
cout<<endl;
}
}
int main()
{
long long n,a,f,i,j;
cin>>n;

for(i=0;i<n;i++)
{
cout<<endl;
cin>>a;
if(a>9)
return 0;
cin>>f;
wave(a,f);
if(i!=n-1)
cout<<endl;
}
return 0;
}

rifat_07
New poster
Posts: 1
Joined: Wed Oct 14, 2009 8:04 pm

About 488

Post by rifat_07 »

remove after ac
Last edited by rifat_07 on Fri Apr 02, 2010 11:46 pm, edited 1 time in total.

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: Help me please.

Post by sohel »

You can use the search option [located at the top right of the screen] to find existing threads of this problem! You will find lots of discussions there.
- Don't create a new thread if one already exists.. and also make sure you use an informative subject. "Help me please" doesn't actually say much about the problem you are having trouble with. :)

Good Luck!

aya
New poster
Posts: 1
Joined: Thu Oct 29, 2009 10:05 am

wrog answer in triangle wave

Post by aya »

i dont know where the problem pleas help
#include <iostream>
using namespace std;



int main()
{
int *mag;
int * freq;


int cases=0;
int count=0;
cin>>cases;
cout<<endl;
mag= new int [cases];
freq=new int [cases];

for(int i=0;i<cases;i++)
{
cin>>mag;
cin>>freq;

cout<<endl;
}


int y=0;

while(y<cases)
{
while(count<freq[y])
{

for(int i=1;i<mag[y]+1;i++)
{
for(int j=0;j<i;j++)
cout<<i;
cout<<endl;
}

for(int i=mag[y]-1;i!=0;i--)
{
for(int j=i;j!=0;j--)
cout<<i;
cout<<endl;
}

count++;
if(y ==(cases -1)&& count==(freq[y]))
{
}
else
cout<<endl;


}

count=0;
y++;
}

return 0;
}

r2ro
New poster
Posts: 38
Joined: Thu Sep 25, 2008 9:26 am

Re: wrog answer in triangle wave

Post by r2ro »

You are printing too much new lines.

Noo
New poster
Posts: 1
Joined: Tue Nov 03, 2009 12:28 am

Re: 488 - Triangle Wave

Post by Noo »

This Code always gives me a wrong answer please I want to know why

Code: Select all

    
#include <iostream>
using namespace std;

void Test(int ambitude,int freq)
{
 for(int i=0;i<freq;++i)
    {
         for( int s=1;s<=ambitude;++s)
            {
              for(int w=1;w<=s;++w)
                 cout << s ;
               cout << endl;     
            }
          for( int s=ambitude-1;s>=1;--s)
            {
              for(int w=1;w<=s;++w)
                 cout << s;
                 cout << endl;
            }   
            if(i!=freq-1)
            cout << endl;    
    } 
}
int main(int argc, char *argv[])
{ 
    int* ambitude;
    int* freq;
    int number;
    cin>>number;
    cout << endl;
    ambitude=new int[number];
    freq=new int[number];
    for(int i=0;i<number;++i)
    {
    cin>> ambitude[i] >> freq[i];
    cout << endl;
    }
    for(int i=0;i<number;++i)
    if(ambitude[i]<=9)
    {
       Test(ambitude[i],freq[i]);
    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

[/b]

run2win
New poster
Posts: 1
Joined: Fri Nov 06, 2009 6:10 pm

Re: WA 488

Post by run2win »

Hi,guys!
I've checked the previous posts but can't find what's wrong whit my code,can any one help.
thx

Code: Select all

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>

using namespace std;

int str[9]={1,22,333,4444,55555,666666,7777777,88888888,999999999};   //pre-init
int main(){
//	ifstream fin("input.txt");
	int n;
	scanf("%d",&n);
//	fin>>n;
	for(int i=0; i<n; i++){
		if(i>0)
			printf("\n");
//			cout<<endl;
		int amp,freq;
		scanf("%d%d",&amp,&freq);
//		fin>>amp>>freq;
		for(int j=0; j<freq; j++){
			if(j>0)
				printf("\n");
//				cout<<endl;
			for(int k=1; k<amp; k++){
				printf("%d\n",str[k-1]);
//				cout<<str[k-1];
//				cout<<endl;
			}
			for(int k=amp; k>0; k--){
				printf("%d",str[k-1]);
//				cout<<str[k-1];
				if( (i==n-1) && (j==freq-1) && (k==1));
				else
					printf("\n");
//					cout<<endl;
			}
		}
	}
	cin.get();
	cin.get();
	return 0;
}

doitnow
New poster
Posts: 2
Joined: Thu Jan 28, 2010 5:03 am

488 Triangle Wave ??????????????

Post by doitnow »

pls help me, what's wrong with this code ?????????????

Code: Select all

#include <iostream>

using namespace std;



void printWave(int amplitude, int frequency)

{

	for (int i = 0; i < frequency; i++)

	{

		for (int j = 0; j <= amplitude; j++)

		{

			for (int k = 0; k < j; k++)

				cout << j;

			cout << endl;

		}

		for (int j = amplitude - 1; j >= 1; j--)

		{

			for (int k = 0; k < j; k++)

				cout << j;

			cout << endl;

		}

	}

}





int main()

{

	int freq, amp;

	int waveNum = 0;

	

	cin >> waveNum;

	if (cin.eof())

		return -1;



	while (waveNum -- )

	{

		cin >> amp >> freq;

		if (cin.eof())

			return -1;

		printWave(amp, freq);

	}



	return 0;

}

Deb20
New poster
Posts: 2
Joined: Mon Sep 13, 2010 4:26 pm

488

Post by Deb20 »

What's wrong with this code ?????? I got WA more and more... Can anyone help me plz ?????


#include <iostream>
using namespace std;
int main()
{
long long a,f,n_c;
cin >> n_c;
// temp=n_c;
// while (n_c--)
while (n_c--)
{
cin >> f >> a;
while(a--)
{
long long i,j,n;

n=(f*2)-1;
int am=2;
for(i=1;i<=n;i++)
{
//if (i>0){
//cout << endl;
//}
if(i<=((n/2)+1))
{

for(j=1;j<=i;j++)
{
cout << i;
}

}

else
{

for(j=(n+1)-i;j>=1;j--)
{
cout << i-am;
}
am=am+2;
}

if(i<n)
cout << endl;
else{
if(n_c>0)
cout << endl;
else if(n_c==0&&a!=0)
cout << endl;
}


}


if(a!=0)
{
cout << endl;
}


}
if(n_c!=0)
cout << endl;
}
}

talz13
New poster
Posts: 5
Joined: Sat Oct 18, 2008 7:20 pm

Re: WA 488

Post by talz13 »

Can't figure out what's wrong with my answer. I don't print a blank line at the top of my output, I only output a blank line between frequency loops and cases, and I don't print anything after the last number of the last frequency loop of the last case. I'm using cin and cout, but I still come in with time to spare (~1.4s).

Code: Select all

Got AC...
Last edited by talz13 on Mon Sep 20, 2010 4:25 pm, edited 1 time in total.

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

Re: WA 488

Post by helloneo »

talz13 wrote:Can't figure out what's wrong with my answer. I don't print a blank line at the top of my output, I only output a blank line between frequency loops and cases, and I don't print anything after the last number of the last frequency loop of the last case. I'm using cin and cout, but I still come in with time to spare (~1.4s).
You should print '\n' after the last test case..
Remove your code if you get AC :)

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

Re: WA 488

Post by dewsworld »

I cannot find what my problem is :(
Can anyone help pleasure ...

Code: Select all

#include <stdio.h>

int   main()
{
    int     noTest ;
    int     a, f ;
    int     i, j, k;

    scanf("%d", &noTest ) ;

    while( noTest-- )
    {
        scanf("%d%d", &a, &f) ;

        for( i = 0 ; i < f ; i++ )
        {
            for( j = 0 ; j < a ; j++ )
            {
                for( k = 0 ; k <= j ; k++)
                    printf("%d", j+1 ) ;

                putchar('\n');
            }
            for( j = a-1 ; j > 0 ; j-- )
            {
                for( k = 0 ; k < j ; k++ )
                    printf("%d", j) ;

                if( !(i== f-1 && j == 1) )
                    putchar('\n') ;
            }

            if( i != f-1 )
                putchar('\n') ;
        }

    }

    return 0;
}

sirius
New poster
Posts: 4
Joined: Sat Aug 09, 2008 6:51 am

Re: WA 488

Post by sirius »

Hi dewsworld

You have a problem with '\n' newline.

For this input

Code: Select all

4

1
9

9
1

1
1

9
9
your output

Code: Select all

1

1

1

1

1

1

1

1

1
1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
11
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
where it should be

Code: Select all

1

1

1

1

1

1

1

1

1

1
22
333
4444
55555
666666
7777777
88888888
999999999
88888888
7777777
666666
55555
4444
333
22
1

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
Good luck!

mashaheer
New poster
Posts: 4
Joined: Sat Nov 20, 2010 2:23 pm

Re: WA 488

Post by mashaheer »

finally i got AC! :D
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.
i didnt do bold part: but i got AC!

Post Reply

Return to “Volume 4 (400-499)”