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 1001. Reverse Root

[PYTHON] Can anyone please tell me why this gives wrong answer on test 1? It works fine with my compiler fo a lot of cases.
Posted by rayneh 18 Jul 2019 02:45
import math
import re

input_string =  ''

while True:
    line = input()
    if line:
        input_string = input_string + ' ' + line
    else:
        break


input_digits = [int(x) for x in input_string.replace('\n',' ').replace('\t', ' ').split()]
input_digits = input_digits[::-1]

for int in input_digits:
        sqr_root = math.sqrt(int)
        print(format(sqr_root, '.4f'))



#Thanks for the help guys!
Re: [PYTHON] Can anyone please tell me why this gives wrong answer on test 1? It works fine with my compiler fo a lot of cases.
Posted by VioletVal 12 Aug 2019 10:01
I tested your code on some online compilers, and the last two answers were printed, but not the first two. It looks like your algorithm correctly read the first line, but because there were empty lines for the next couple lines, your break statement kept the code from reading the last two lines in the example testcase. You need to change the code so it can read all the lines, even the ones that come after empty lines.