ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1226. esreveR redrO

Why is this crashing to WA#1 (Python)?
Posted by Kasparow 8 May 2017 18:46
import sys

def reverse(i):
    if len(i) == 1:
        return i
    else:
        return i[len(i)-1]+reverse(i[:len(i)-1])

def getReverseLine(s):
    start = 0
    for i in range(len(s)):
        if (ord(s[i]) < 123 and ord(s[i]) > 64) and (ord(s[i]) < 91 or ord(s[i]) > 96):
            if i == len(s)-1:
                if start < i:
                    s = s.replace(s[start:i+1], reverse(s[start:i+1]))
        else:
            if start < i:
                s = s.replace(s[start:i], reverse(s[start:i]))
                start = i+1
            else:
                start += 1
    return s

lines = []
while True:
    line = sys.stdin.read()
    if line == '':
        break
    lines.append(getReverseLine(line))

text = '\n'.join(lines)

print text