44 lines
820 B
Python
44 lines
820 B
Python
"""
|
|
name: Nicholas Tamassia
|
|
|
|
Honor Code and Acknowledgments:
|
|
|
|
This work complies with the JMU Honor Code.
|
|
|
|
Comments here on your code and submission.
|
|
"""
|
|
|
|
|
|
def is_palindrome(s: str) -> bool:
|
|
return s == s[::-1]
|
|
|
|
|
|
def palindrome_partitions(s: str) -> int:
|
|
if len(s) == 0:
|
|
return 1
|
|
|
|
sum = 0
|
|
|
|
for i in range(1, len(s) + 1):
|
|
left = s[:i]
|
|
right = s[i:]
|
|
|
|
if is_palindrome(left):
|
|
sum += palindrome_partitions(right)
|
|
|
|
return sum
|
|
|
|
|
|
# All modules for CS 412 must include a main method that allows it
|
|
# to imported and invoked from other python scripts
|
|
def main():
|
|
n: int = int(input())
|
|
|
|
for i in range(0, n):
|
|
in_str = input().strip()
|
|
print(palindrome_partitions(in_str))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|