Hello! I'm trying to submit a solution to the PALIN problem (The Next Palindrome). My solution wouldn't run in the specified time limit, and I think it's because of how I do I/O.

This is my code:

if __name__ == '__main__':
    import sys
    numCases = int(sys.stdin.readline().strip())
    for line in sys.stdin.readlines(numCases):         
        print nextPalindrome(int(line.strip()))

I've tried a couple of variations on this, as well. How can I tell if my program is too slow because of the algorithm I use, or because I/O is not functioning properly?

Thank you for your time!

  • created

    Jan '08
  • last reply

    Aug '08
  • 1

    reply

  • 120

    views

  • 2

    users

7 months later

try this

if __name__ == '__main__':
    import sys
    data = sys.stdin.read().split()
    for i in range(1, len(data)):         
        print nextPalindrome(int(data[i]))

but i think it's an algorithm problem
You can use psyco also

Suggested Topics

Want to read more? Browse other topics in Python or view latest topics.