## 488 - Triangle Wave

Moderator: Board moderators

Iwashere
New poster
Posts: 20
Joined: Mon Aug 11, 2003 1:50 pm
Location: Singapore
Can anyone help me with my code. I tried it and it looked alright, but i got WA Code: Select all

``````#include <stdio.h>

int amp, fre, no, i, l;

int main(){
scanf ("%d",&no);
for (; no>0; no--){
scanf("%d %d",&amp,&fre);
for (; fre>0; fre--){
for (i=1; i<=amp; i++){
for (l=i; l>0; l--){
printf("%d",i);
}
printf("\n");
}
for (i=amp-1; i>1; i--){
for (l=i; l>0; l--){
printf("%d",i);
}
printf("\n");
}
if ((no==1)&&(l==0)&&(fre==1)){
printf("1");
}
else{
printf("1\n\n");
}
}
}
return 0;
}
``````

Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia
Just change the part
[c]
}
for (i=amp-1; i>1; i--){
for (l=i; l>0; l--){
printf("%d",i);
}
printf("\n");
}
[/c]

with
[c]
}
for (i=amp-1; i>=1; i--){
for (l=i; l>0; l--){
printf("%d",i);
}
printf("\n");
}
printf("\n");
[/c]

And remove the part
[c]
if ((no==1)&&(l==0)&&(fre==1)){
printf("1");
}
else{
printf("1\n\n");
}
[/c]

And after the part
[c]
scanf("%d",&no);
[/c]
put
[c]
if(k) printf("\n\n");
else k=1;
[/c]
So you have to add one more variable.
Good Luck!!
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.

Iwashere
New poster
Posts: 20
Joined: Mon Aug 11, 2003 1:50 pm
Location: Singapore
Hey, I got AC, thanks for your help!

claire yan
New poster
Posts: 6
Joined: Thu Oct 02, 2003 7:02 am

i got WA and WA but i tried and tried
#include <iostream>
#include <stdio.h>
using namespace std;
////////////////////////////

int main()
{
int i = 0;
int j = 0;
int k = 0;
int m = 0;
int temp;
int amp;
int fre;
while(cin>>amp>>fre)
i = i+1;
temp = i--;
for(i = 0; i < temp; i++)
{
for(j = 0; j < fre; j++)
{
for(k=1;k <= amp;k++)
{
for(m = 1;m <= k ; m++)
cout<< k;
cout<<endl;
}
for(k = amp-1;k >= 1; k--)
{
for(m = 1;m <=k ; m++)
cout<<k;
cout<<endl;
}
cout<<endl;
}
cout<<endl;
}
return 0;
}[/cpp]

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Contact:
the problem is a multiple input problem ( blue tick ) u must consider this.

claire yan
New poster
Posts: 6
Joined: Thu Oct 02, 2003 7:02 am
thanks a lot
^^

New poster
Posts: 8
Joined: Mon Sep 29, 2003 3:13 pm

### 488-WA I know that's multiple input

I don' know what is wrong with it

Code: Select all

``````const
tab:array[1..9] of string=
('1','22','333','4444','55555','666666','7777777','88888888','999999999');
var
a,i,q,n,m,j:longint;
begin
while not eof do
begin
if n>0 then
for i:=1 to m do
begin
for j:=1 to n do
writeln(tab[j]);
for j:=n-1 downto 1 do
writeln(tab[j]);
if i<>m then
writeln;
end;
end;
end.
``````

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

### 488....Why WA?

Here is my code:

[c][/c]

I can't see what is wrong with it!
if someone knows...pleas help me
Last edited by midra on Thu Apr 15, 2004 2:51 am, edited 1 time in total.

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
This is a blue tick problem.
That is the first line of input is the number of test cases, eventhough this is not shown in the sample input. midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:
Thank you Shamin!
I finally got AC!   good bye!!!!

randomtaiwanese
New poster
Posts: 32
Joined: Fri Oct 01, 2004 10:53 pm

### 488 WA odd...

[java]import java.io.IOException;
import java.util.StringTokenizer;

class Main
{
{
byte lin[]=new byte;
int lg=0,car;
try
{
while(true)
{
if ((car<0)||(car=='\n'))
break;
lin[lg++]+=car;
}
}
catch(IOException e)
{
return(null);
}
if ((car<0)&&(lg==0))
return(null);
return (new String (lin, 0, lg));
}
public static void main(String[] args)
{
Main newMain = new Main();
newMain.start();
}
void start()
{
int[][] in = new int;
int c = 0;
int max = 0;
boolean inb = true;
String input;
{
if(max==0)
max = Integer.parseInt(new StringTokenizer(input).nextToken());
else if(inb)
{
in[c] = Integer.parseInt(new StringTokenizer(input).nextToken());
inb = false;
}
else
{
in[c] = Integer.parseInt(new StringTokenizer(input).nextToken());
c++;
inb = true;
}
if(c==max)
{
for(int i=0;i<max;i++)
for(int f=0;f<in;f++)
{
for(int a=1;a<in;a++)
{
for(int t=1;t<=a;t++)
System.out.print(a);
System.out.println();
}
for(int a=in;a>0;a--)
{
for(int t=a;t>=1;t--)
System.out.print(a);
System.out.println();
}
if(f!=in-1)
System.out.println();
}
break;
}
}
}
}[/java]

Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET
Hmm, I didn't completely see your code, just a glance... It seems that you've not handled the multiple input case. Note that if u have an earlier version of problemset, the problem was marked as a blue flag problem there.
You should never take more than you give in the circle of life.

New poster
Posts: 18
Joined: Fri Jan 07, 2005 9:35 pm

### 488 why WA???

plz help me out.

#include<stdio.h>
#include<iostream.h>
int main()
{
int a,f,i,j,k,l,m,flag;
cin>>a>>f;

flag=0;
for(i=1;i<=f;i++)
{
if(flag==1)
cout<<"\n";
for(j=1;j<=a;j++)
{
for(k=1;k<=j;k++)
cout<<j;
cout<<"\n";
}
for(l=a-1;l>=1;l--)
{
for(m=1;m<=l;m++)
cout<<l;
cout<<"\n";
}
flag=1;
}

return 0;
}

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
thank you. i got AC . actually it was my foolish mistake 