Search This Blog

Wednesday, 1 November 2023

String Problem

Description

In a certain encrypted message which has information about the location(area, city), the characters are jumbled such that first character of the first word is followed by the first character of the second word, then it is followed by second character of the first word and so on


In other words, let’s say the location is bandra,mumbai


The encrypted message says ‘bmaunmdbraai’.


Sample Input:

bmaunmdbraai


Sample Output:

bandra,mumbai


Let’s say the size or length of the two words wouldn’t match then the smaller word is appended with # and then encrypted in the above format.


With this in mind write a code to identify the right location and print it as place,city.


Solution:


            import ast,sys

            input_str = sys.stdin.read()

            print(input_str[::2]+","+input_str[1::2])

No comments:

Post a Comment

String Problem

Description In a certain encrypted message which has information about the location(area, city), the characters are jumbled such that first ...