Expand String – K Characters

The program must accept three integers XY and K as the input. The program must form a string with lower case alphabets starting from the Xth alphabet to the Yth alphabet in the English alphabet set. The program must stretch the string as short as possible so that the string contains at least K characters. A stretch is to repeat each character in a string the same number of times. Then the program must print the resulting string as the output.

Boundary Condition(s):
1 <= X < Y <= 26
1 <= K <= 1000

Input Format:
The first line contains X, Y and K separated by a space.

Output Format:
The first line contains the resulting string.

Example Input/Output 1:
Input:
1 5 13

Output:
aaabbbcccdddeee

Explanation:
Here X = 1Y = 5 and K = 13.
1st lower case alphabet is ‘a‘.
5th lower case alphabet is ‘e‘.
So the string is formed as “abcde“.
Then the string is stretched as “aaabbbcccdddeee” whose length is 15 (13 <= 15).

Example Input/Output 2:
Input:
1 5 20

Output:
aaaabbbbccccddddeeee

Example Input/Output 3:
Input:
24 25 9

Output:
xxxxxyyyyy

X,Y,K=map(int,input().split())
String=" abcdefghijklmnopqrstuvwxyz"
temp=(Y-X)+1
while 1:
    if(K%temp==0):
        break
    else:
        K+=1
for index in range(X,Y+1):
    print(String[index]*(K//temp),end="")
Previous Article

Reverse Every Word

Next Article

Integer - Exactly Three Digits

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *