Pattern Printing Middle Letter - Odd Length String

 Coding Problem Keys 

 Pattern Printing Middle Letter - Odd Length String 

 Problem Statement 

An odd length string S is passed as the input. The program must print the pattern as described below.

Let L be the length of the string and M denote the middle position of the string S. The characters in the string are a(1),...., a(M), .... a(L).

    - The first line will contain the middle letter a(M) of S in the extreme right.
    - Then in each subsequent line, the letter after the middle letter from a(M + 1) to a(L) is appended to the line output.
    - After the end of the string a(L) is reached, in each subsequent line, the letters from the beginning to the middle letter, a(1) to a(M-1) are appended to the line output.

Note: Asterisk * will be used to pad in the front so that each line has L characters.

 Input Format 

The first line contains the S.

 Output Format 

L lines as output where L is the length of the string S.

 Boundary Condition(s) 

3 <= L <= 1001.

 Example Input/Output 1 

 Input 

CRY

 Output 

**R
*RY
CRY

 Example Input/Output 2 

 Input 

PROGRAM

 Output 

******G
*****GR
****GRA
***GRAM
**GRAMP
*GRAMPR
GRAMPRO

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

a=input().strip()
a=a[len(a)//2:]+a[:len(a)//2]
for i in range(1,len(a)+1):
    print("*"*(len(a)-i),a[:i],sep='')
#Published By PKJCODERS

 Alter 

n=input().strip();p=1
newstr=n[len(n)//2]+n[len(n)//2+1:]+n[:len(n)//2]
for i in range(len(n)-1,-1,-1):
    print("*"*i+newstr[:p])
    p+=1
#Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Nielsen

Mango Distribution

Prime or Not - CTS Pattern

Consonants Count in Sliding Window

HCLTech

Split String & Sort