Middle Pattern
Submissions: 8473   Accuracy:

26.66%

  Difficulty: Basic   Marks: 1

Given an odd length word your task is to complete the function printPattern that takes a string s as its argument and prints it from the middle of the word such that it follows the following pattern.
 

Input: PROGRAM                            Input: RAT
Output:                                   Output:
            G                                       A
          GR                                      AT  
        GRA                                     ATR
      GRAM
    GRAMP
  GRAMPR
GRAMPRO

The above is proper shaped pattern for the test case, but when
printed in a single line it becomes as shown in the output. 

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of a single line containing an odd length string s.

Output:
Corresponding to each test case in a new line print the pattern in a  single line where each row of the pattern is separated by a "$" instead of a new line.

Constraints:
1 ≤ T ≤ 20
1<=size of string(s)<=20

Example(To be used only for expected ouput):
Input
2
PROGRAM
RAT

Output

            G$          GR$        GRA$      GRAM$    GRAMP$  GRAMPR$GRAMPRO$
    A$  AT$ATR$

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.