SONICBOOM -Editorial

PROBLEM LINK:

Practice
Contest

Author: rocknot
Tester: root_rvl
Editorialist:rocknot

DIFFICULTY:

EASY

PREREQUISITES:

Implementation

PROBLEM:

Jay recently got selected in Space-X and was working on a super sonic plane. The plane travel’s at a speed more than the speed of sound and at this speed sound barier breaks and the Plane is slowed down by sonic Booms. Due to this the speed the plane should have achieve is not reached, so Jay needs to modify the plane.

After few months of research they found a special pattern that reduces the effect of sonic boom. You are given an integer N

You need to find the pattern according to the given value of N

for N

=5 pattern will be as follows

  *
  *1*
  *121*
  *12321*
  *1234321*
  *123454321*
  *1234321*
  *12321*
  *121*
  *1*
  *

HINT:

Observe the pattern increasing and and decreasing sequence and * at the start and end of each line.

SOLUTIONS:

Solution
#include <bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
    int N;
    cin>>N;
    cout<<"*\n";
    for(int i=1;i<=N;i++){
        for(int j=1;j<=i;j++){
            if(j==1)
                cout<<"*";
            cout<<j;
        }
        for(int j=i-1;j>=1;j--){
            cout<<j;
        }
        cout<<"*";
        cout<<"\n";
    }
    for(int i=N-1;i>=1;i--){
        for(int j=1;j<=i;j++){
            if(j==1)
                cout<<"*";
            cout<<j;
        }
        for(int j=i-1;j>=1;j--){
            cout<<j;
        }
        cout<<"*";
        cout<<"\n";
    }
    cout<<"*\n";
}
return 0;

}