|
|
back to boardpython3.3 Time limit exceeded 9th test Posted by Exxtay 19 Feb 2013 14:34 How to optimize my code? I know there is a lot of convertions from one type to another. How to avoid it? Or problem of speed not in convertions? import sys, re, math str1 = str(sys.stdin.readlines()) Data = re.findall('\\b\\d+\\b', str1) for i in reversed (Data): print('%.4f' % math.sqrt(float(i))) Edited by author 19.02.2013 23:58 Re: python3.3 Time limit exceeded 9th test Posted by Exxtay 22 Feb 2013 05:24 solution, which worktime is 1.85 import sys, re from math import sqrt as sq def find_numbers(f): for line in f: for word in line.split(): if word.isdigit(): yield float(word) lst = list(find_numbers(sys.stdin)) lst.reverse() for x in lst: print('%.4f' % sq(x)) |
|
|