https://uva.onlinejudge.org/external/4/488.pdf
    
Here it's an easy problem but there's only one trick that is "There is a blank line after each separate waveform, excluding the last one" . It's means you have to print a blank line after every waveform except the last one so in last line when programme will terminate there no blank line is needed . 
1 . As it is said in the sample input that  3 is the amplitude which means how high the horizontal line will be and frequency is 2 that means how times same triangle should be print . 
2 . It is also said that Amplitude will never been greater than 9 so you can store 1,22,333,4444,55555 just like this until 9 into an string array and print those how many times it's needed to print. 
N.B : I have got 10 times presentation error for problem of printing blank line so handle it carefully . 
An accepted code is given below : 
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string wave[100]={"1","22","333","4444","55555","666666","7777777","88888888","999999999"};
    int i,t,j,a,b;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&a,&b);
        while(b--)
        {
            for(j=0;j<a;j++)
            {
                cout<<wave[j]<<endl;
            }
            for(j=a-2;j>=0;j--)
            {
                cout<<wave[j]<<endl;
            }
            if(b || t)
            {
            printf("\n");
            }
        }
    }
    return 0;
}
 
 
No comments:
Post a Comment