Created
June 20, 2016 01:20
-
-
Save DaniloOliveira28/e9bcb326bf0faa4cc2c17952dc7434ce 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
def n_lower_chars(string): | |
return sum(1 for c in string if c.islower()) | |
def format_word(word): | |
if word == word.upper() or word == word.lower(): | |
return 0 | |
M = dict() | |
M[0] = 0 | |
for i in range(1, len(word)): | |
if word[i] == word[i].lower(): | |
M[i] = M[i - 1] | |
elif word[i] == word[i].upper(): | |
M[i] = min(M[i - 1] + 1, n_lower_chars(word[:i])) | |
return M[len(word) - 1] | |
if __name__ == "__main__": | |
print format_word("AaAaAAAaAAAaAAAAAA") | |
print format_word("AaAaAAAaAAAaAAaaaaaaA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment