Created
June 2, 2015 18:56
-
-
Save buzibu/06b0d056d6d2e03c9058 to your computer and use it in GitHub Desktop.
Aлгоритми
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
# Is_Palindrome(String)-> Boolean | |
# Checks if a text is palindrome or not (True ot False) | |
def Is_Palindrome(input_string): | |
string_len=len(input_string) | |
if string_len% 2 == 0: | |
beginning=input_string[:string_len/2] | |
ending=input_string[string_len/2:] | |
else: | |
beginning=input_string[:(string_len-1)/2] | |
ending=input_string[(string_len-1)/2+1:] | |
if beginning==ending[::-1]: | |
return True | |
else: | |
return False | |
# String_rotation(String, Integer)-> String | |
# Makes string rotation at given position | |
def String_rotation(My_string, position): | |
return My_string[position:]+My_string[:position] | |
def main_function(main_string): | |
palindrome_found=False | |
for i in range(len(main_string)): | |
current_rotation=String_rotation(main_string,i) | |
if Is_Palindrome(current_rotation): | |
print(current_rotation) | |
palindrome_found=True | |
if not palindrome_found: | |
print('NONE') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment