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 1074. Very Short Problem

WA2 with re
Posted by Alexandr Vasilyev 7 Jul 2016 16:25
import re
fl = re.compile('[+-]?[1234567890]*\.[1234567890]*([Ee][+-]?[1234567890]+)?')
lf = re.compile('[+-]?[1234567890]+([Ee][+-]?[1234567890]+)?')
nums = []
while True:
    first = input()
    if first == '#':
        break
    nums.append((first, int(input())))
for num in nums:
    num0 = num[0]
    if not (re.fullmatch(fl, num0) or re.fullmatch(lf, num0)):
        print('Not a floating point number')
        continue
    try:
        e_pos = num0.index('e')
        exp = int(num0[e_pos + 1:])
        num0 = num0[:e_pos]
    except:
        try:
            e_pos = num0.index('E')
            exp = int(num0[e_pos + 1:])
            num0 = num0[:e_pos]
        except:
            exp = 0
    pm = num0[0]
    if pm in ['+', '-']:
        num0 = num0[1:]
    else:
        pm = '+'
    if pm == '+':
        pm = ''
    if exp > 0:
        num0 += '0' * exp
    elif exp < 0:
        num0 = '0' * (-exp) + num0
    try:
        dot_pos = num0.index('.')
    except:
        dot_pos = len(num)
        num0 += '.'
    new_dot_pos = dot_pos + exp
    num0 = num0[:dot_pos] + num0[dot_pos + 1:]
    num0 = num0[:new_dot_pos] + '.' + num0[new_dot_pos:]
    while num0.startswith('0'):
        num0 = num0[1:]
    if num0.startswith('.'):
        num0 = '0' + num0
    num0 += '0' * num[1]
    num0 = num0[:num0.index('.') + num[1] + 1]
    if num0.endswith('.'):
        num0 = num0[:-1]
    print(num0)