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

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Re: WA 488

print a blank line between two consecutive cases.

tajbir2000
New poster
Posts: 19
Joined: Fri Sep 05, 2008 6:39 pm
Location: bangladesh
Contact:

488 - Triangle Wave

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

return 0;
}

Moshiur Rahman
New poster
Posts: 13
Joined: Mon Sep 08, 2008 6:57 pm
Location: State University of Bangladesh

Re: 488wa!!!!!!!please help me!!!!!!!!where is the problem

You must print blank lines between testcases also....

read the problem statement again carefully.....
Never think too hard, let ideas come to you...

f.a.reza
New poster
Posts: 5
Joined: Wed Oct 08, 2008 10:13 am

Re: WA 488

where is the mistake?i m continuously getting wrong answer
#include<stdio.h>

int main()
{
int i,j,k,l,x,y,n;
scanf("%d",&n);

for(i=1;i<=n;i++)
{ printf("\n");
scanf("%d",&x);
scanf("%d",&y);

for(j=1;j<=y;j++)
{
for(k=1;k<=x;k++)
{
for(l=1;l<=k;l++)printf("%d",k);
printf("\n");
}
for(k=x-1;k>=1;k--)
{

for(l=1;l<=k;l++)printf("%d",k);
if(j!=y||k!=1)printf("\n");
}

if(j!=y)printf("\n");
}

}

return 0;
}

vinocit
New poster
Posts: 10
Joined: Mon Oct 13, 2008 10:11 am

Re: 488 TLE

WA here could any one check this pls
#include<iostream>
using namespace std;
int main()
{
int noofcases;
char *s[9]={"1","22","333","4444","55555","666666","7777777","88888888","999999999"};
int flag=0;
cin>>noofcases;
while(noofcases)
{
noofcases--;
if(!flag)cout<<"\n";
flag=1;
int n,f;
cin>>n>>f;
for(int i=0;i<f;i++){
for(int j=0;j<n;j++){
cout<<s[j];
cout<<"\n";
}
for(int j=n-2;j>=0;j--){
cout<<s[j];
cout<<"\n";
}

}
}
return 0;
}

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 488 TLE

To vinocit
Problem says:
NOTE: There is a blank line after each separate waveform, excluding the last one.
See the output format.

vinocit
New poster
Posts: 10
Joined: Mon Oct 13, 2008 10:11 am

Re: 488 TLE

Thanks a lot i got AC

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: WA 488

pls tell me why i'm getting WA..

#include<stdio.h>

int main()
{
long long int n,i=0,k,j,m,p;

scanf("%lld",&n);

while(i<n)
{
printf("\n");
scanf("%lld\n%lld",&m,&p);
printf("\n");

int o=0;

while(o<p)
{
for(j=1;j<=m;j++)
{
for(k=1;k<=j;k++)
printf("%lld",j);
printf("\n");
}
for(j=m-1;j>=1;j--)
{
for(k=1;k<=j;k++)
printf("%lld",j);
printf("\n");
}
o++;
if(o!=p) printf("\n");
}
i++;

}

return 0;
}

i realy need ur help..

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 488wa!!!!!!!please help me!!!!!!!!where is the problem

Why i got WA in this problem ???????
why why why ?
i cant understand ..
pls help me.......

Code: Select all

``````removed after AC..
``````
Last edited by pok on Sat Dec 20, 2008 10:47 pm, edited 1 time in total.

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 488wa!!!!!!!please help me!!!!!!!!where is the problem

Change this portion of your code:

Code: Select all

``````      printf("\n");
scanf("%lld\n%lld",&m,&p);
printf("\n");
``````
into this:

Code: Select all

``````      scanf("%lld\n%lld",&m,&p);
if(i!=0) printf("\n");
``````
That will do.
May be tomorrow is a better day............

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 488wa!!!!!!!please help me!!!!!!!!where is the problem

Thanks.. Articuno..
take care..
God bless you..

tajbir2000
New poster
Posts: 19
Joined: Fri Sep 05, 2008 6:39 pm
Location: bangladesh
Contact:

Re: 488wa!!!!!!!please help me!!!!!!!!where is the problem

i have got ac......... i had missed it
((((The outputs of two consecutive cases will be separated by a blank line.)))

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 488 problem

whats wrong with my code??
WA.
#include<stdio.h>

int main()

{

int amp,freq;

int ncase,i,k,l;

scanf("%d",&ncase);

while(ncase>0)

{
scanf("\n\n%d",&amp);
scanf("\n%d",&freq);

for(i=1;i<=freq;i++)

{
for(k=1;k<=amp;k++)

{
printf("%d",k);
for(l=1;l<k;l++)

{
printf("%d",k);

}

printf("\n");
}

for(k=amp-1;k>0;k--)

{
printf("%d",k);
for(l=1;l<k;l++)

{
printf("%d",k);

}

printf("\n");
}
if(i<freq)
printf("\n");

}

ncase--;

}

return 0;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

Harlan
New poster
Posts: 1
Joined: Thu Jul 09, 2009 5:52 am

Re: 488wa!!!!!!!please help me!!!!!!!!where is the problem

Where is the problem??

?

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

main()
{
int t, ax, ay, fx, k = 1, tx = 0, ty = 0;

scanf(" %d", &t);

int a[t], f[t];

printf("\n");

while(tx < t)
{
scanf(" %d", &a[tx]);
scanf(" %d", &f[tx]);
printf("\n");
tx++;
}

while(ty < t)
{
fx = 1;
while(fx <= f[ty])
{
k = 1;
for(ay = 1;ay < a[ty] * 2;ay++)
{
if(ay <= a[ty])
{
for(ax = 1;ax <= ay;ax++)
{
printf("%d", ay);
}
}
else
{
for(ax = a[ty] - k;ax > 0;ax--)
{
printf("%d", a[ty] - k);
}
k++;
}
printf("\n");
}
printf("\n");
fx++;
}
ty++;
}

system("PAUSE");
return 0;
}

Thanks!!!

Rudy Lie
New poster
Posts: 1
Joined: Sat Sep 12, 2009 9:01 am

Re: 488 TLE

Anybody could help me getting out of TLE ??
this is my code and please check it out which makes it slow....

Code: Select all

``````import java.util.Scanner;
public class Main
{
public static void main (String [] sun)
{
Scanner input = new Scanner (System.in);
int n = input.nextInt();
int [] num = { 1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999 };

int f, i, A, F;
while (n-->0)
{
A = input.nextInt();
F = input.nextInt();
for (f=1; f<=F; f++)
{
for (i=0; i<A; i++)
{
System.out.printf ( "%d\n", num[i]);
}
for (i=A-2; i>=0; i--)
{
System.out.printf ( "%d\n", num[i]);
}
System.out.printf ("\n");;
}
}
}
}``````
Please reply me as soon as possible....thanx anyway...