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

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

Re: stupid......problem.

Post by helloneo »

Obaida wrote:Now look at my output.... I thik thats good.... but still WA
Actually your code prints output this way.. :-)

\n
2\n
\n
3\n
2\n
1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1\n
\n
3\n
2\n
1\n
22\n
333\n
22\n
1\n
\n
1\n
22\n
333\n
22\n
1\n
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Strange....

Post by Obaida »

I think I can't read you.... still WA....
look at my code...... what should be edited...

Code: Select all

Removed
Last edited by Obaida on Sat Mar 01, 2008 10:58 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
AcmNightivy
New poster
Posts: 36
Joined: Tue Dec 04, 2007 10:20 am

Post by AcmNightivy »

I change in using stdio..but still WA..Help!!Thanks!!

Code: Select all

#include <stdio.h>

int main ()
{
	int i, j, k;
	int caseNum;
	int a, f;
	char num[10][10] = {"", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"};

	scanf ("%d", &caseNum);

	for (i = 0; i < caseNum; i++)
	{
		scanf ("%d%d", &a, &f);

		for (j = 0; j < f; j++)
		{
			for (k = 1; k <= a; k++)
			{
				printf ("%s\n", num[k]);
			}
			k = k - 2;
			for (; k >= 1; k--)
			{
				printf ("%s\n", num[k]);
			}

			//if (i != caseNum - 1)
			printf ("\n");
		}	
	}
	return 0;
}
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Still WA....

Post by Obaida »

Some one please could tell me from my above code... that where is the extra \n in my program.... I couldn't find it.... But still I had to belive because I am getting WA in this problem...... :cry:
try_try_try_try_&&&_try@try.com
This may be the address of success.
CSEDU_1323
New poster
Posts: 10
Joined: Mon Feb 25, 2008 8:22 pm
Location: Dhaka, Bangladesh.

Post by CSEDU_1323 »

hi,
Obaida, helloneo trace out ur error u print a extra new line in d front

use if(l>= 1 &&l<n)
instead if(l>= 0 &&l<n)
will do ur work

&&

u don't need 2 take test case more than once

HOPE THIS HELPS
--- B HAPPY & KEEP SMILING ------
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Yes...

Post by Obaida »

Thank You very much.....! I got Accepted..... But in the instruction of the program it is mentoned that we had to print a blank line after test case....
But afterall thank you.... very much....
try_try_try_try_&&&_try@try.com
This may be the address of success.
pwilt
New poster
Posts: 2
Joined: Wed Apr 09, 2008 6:59 pm

Re: 488 - PRESENTATION ERROR!

Post by pwilt »

I seem to be getting the answer correct (tried to follow the formatting in the other posts to the letter) but I'm still getting WA from the judge. Can anybody point out something that I've missed?

Code: Select all

#include <iostream>
#include <string>

using namespace std;

int main(){
    int tc;
    cin >> tc;
    string nums[9] = {"1","22","333","4444","55555","666666","7777777","88888888","999999999"};
    
    short amp, freq, j;
    
    for (int i = 1; i <= tc; i++){
        cin >> amp;
        cin >> freq;
        
        for (short k = 1; k <= freq; k++){
            for (j = 0; j < amp; j++){
                cout << nums[j] << endl;
            }
            for (j -= 2; j >= 0; j--){
                cout << nums[j] << endl;
            }
            if (k < freq){
                cout << endl;
            }
        }
        if (i < tc){
            cout << endl;
        }
    }
}
pwilt
New poster
Posts: 2
Joined: Wed Apr 09, 2008 6:59 pm

Re: 488 - PRESENTATION ERROR!

Post by pwilt »

Bump?
t_sergiu
New poster
Posts: 12
Joined: Sun Mar 02, 2008 6:18 am

Re: 488 TLE

Post by t_sergiu »

I am getting a TLE on this problem as well. I would think it wouldn't take any time at all to run this. Can anybody offer some suggestions?
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 488 TLE

Post by Jan »

No idea. Are you sure you are taking input correctly? You can check your solution by sending a solution which just takes the input.
Ami ekhono shopno dekhi...
HomePage
t_sergiu
New poster
Posts: 12
Joined: Sun Mar 02, 2008 6:18 am

Re: 488 TLE

Post by t_sergiu »

Fixed. I was using cin and cout. Switched it to use printf and scanf, and did it in 1/10 of a second.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 488 - PRESENTATION ERROR!

Post by Obaida »

But this is Actually WA...!
Not PE... :o
In "int main()" type you should use "return 0;"
But you didn't do it.
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 488 TLE

Post by hahahaken »

My code got time limit exceeded.
How to reduce the time? Coz I don't know the maximum number of input.

Code: Select all

Removed after AC
Last edited by hahahaken on Fri May 30, 2008 10:33 am, edited 1 time in total.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 488 TLE

Post by Obaida »

If you use array then you can solve the problem by pre-initialization, it can be like:

Code: Select all

int use[10]={0,1,22,333,4444,55555,666666,7777777,88888888,999999999};
then just print the current value of use[i] and make the wave. It will be more faster and efficient.

else you can do it without any use of array then it can be a little slow.

>>may this help you. :wink:
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 488 TLE

Post by hahahaken »

Obaida wrote:If you use array then you can solve the problem by pre-initialization, it can be like:

Code: Select all

int use[10]={0,1,22,333,4444,55555,666666,7777777,88888888,999999999};
then just print the current value of use[i] and make the wave. It will be more faster and efficient.

else you can do it without any use of array then it can be a little slow.

>>may this help you. :wink:
Still TLE
Here's the updated version:

Code: Select all

Removed after AC
Last edited by hahahaken on Fri May 30, 2008 10:34 am, edited 1 time in total.
Post Reply

Return to “Volume 4 (400-499)”