Created
January 15, 2020 03:26
-
-
Save anmolj7/19346802c5cb23f62921d74ab72addd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Problem | |
Write a program that reads a string S and find the minimum number r of applications of the function replace(a,b) to form a palindrome. | |
''' | |
def main(): | |
String = input() #Isn't displaying any string while taking input because | |
#if you're using an online judge to check our answers, then, it'd show wrong answer | |
#because of this. | |
count = i = 0 | |
j = len(String)-1 | |
while i < j: | |
#To be honest, I really wanna know who created the convention of using | |
#i and j as indices... I've gotten so used to it that I can't use any other! | |
if String[i] != String[j]: | |
count += 1 | |
String = String.replace(String[i], String[j]) | |
i += 1 | |
j -= 1 | |
print(count) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment