Page 13 of 19

Re: WA 488

Posted: Thu Sep 17, 2009 9:59 pm
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

488 triangle wave (wrong answer)

Posted: Tue Sep 29, 2009 11:43 pm
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;
}

About 488

Posted: Wed Oct 14, 2009 8:14 pm
by rifat_07
remove after ac

Re: Help me please.

Posted: Wed Oct 14, 2009 8:41 pm
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!

wrog answer in triangle wave

Posted: Thu Oct 29, 2009 10:10 am
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;
}

Re: wrog answer in triangle wave

Posted: Fri Oct 30, 2009 4:14 am
by r2ro
You are printing too much new lines.

Re: 488 - Triangle Wave

Posted: Tue Nov 03, 2009 12:30 am
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]

Re: WA 488

Posted: Fri Nov 06, 2009 6:36 pm
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;
}

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

Posted: Thu Jan 28, 2010 5:08 am
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;

}

488

Posted: Tue Sep 14, 2010 5:10 pm
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;
}
}

Re: WA 488

Posted: Thu Sep 16, 2010 5:05 pm
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...

Re: WA 488

Posted: Sat Sep 18, 2010 5:29 pm
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 :)

Re: WA 488

Posted: Sun Oct 17, 2010 5:06 pm
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;
}

Re: WA 488

Posted: Wed Oct 27, 2010 5:23 am
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!

Re: WA 488

Posted: Tue Nov 23, 2010 4:22 pm
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!