Python Solution For UVA Online Judge 10945: Mother Bear
Today I've successfully solved another UVA problem called Mother Bear (10945) and I wanted to share my solution here.
Please follow the link to see full Problem Description.
You’ll be given many sentences. You have to determine if they are palindromes or not, ignoring case and punctuations. Every sentence will only contain the letters A-Z, a-z, ‘.’, ‘,’, ‘!’, ‘?’. The end of input will be a line containing the word ‘DONE’, which should not be processed
On each input, output ‘You won't be eaten!’ if it is a palindrome, and ‘Uh oh..’ if it is not a palindrome.
Madam, Im adam! Roma tibi subito motibus ibit amor. Me so hungry! Si nummi immunis DONE
You won't be eaten! You won't be eaten! Uh oh.. You won't be eaten!
Understanding the solution
- Taking input string until user enter done
- Converting to lower case so that we can match the reverse string regardless what case user enters in input
- Clean all spaces and punctuations
- Check if the cleaned string is a palindrome or not. Meaning if we reverse the string it should be equal to the previous value.
- We print respective value depending on if the string is palindrome or not.
Please let me know if it helped !