# -*- coding: utf-8 -*-
def main():
maxwidth = 100
print_start()
count = 0
while True:
try:
line = input()
if count == 0:
color = "lightgreen"
elif count % 2:
color = "white"
else:
color = "lightyellow"
print_line(line, color, maxwidth)
count += 1
except EOFError:
break
print_end()
def print_start():
print("
")
def print_end():
print("
")
def print_line(line, color, maxwidth):
print("".format(color))
fields = extract_fields(line)
for field in fields:
if not field:
print(" | ")
else:
number = field.replace(",", "")
try:
x = float(number)
print("{0:d} | ".format(round(x)))
except ValueError:
field = field.title()
field = field.replace(" And ", " and ")
field = escape_html(field)
if len(field) <= maxwidth:
print("{0} | ".format(field))
else:
print("{0:.{1}} ... | ".format(field, maxwidth))
print("
")
def extract_fields(line):
fields = []
field = ""
quote = None
for c in line:
if c in "\"'":
if quote is None: # начало строки в кавычках
quote = c
elif quote == c: # конец строки в кавычках
quote = None
else:
field += c
# другая кавычка внутри строки в кавычках
continue
if quote is None and c == ",": # end of a field
fields.append(field)
field = ""
else:
field += c
# добавить символ в поле
if field:
fields.append(field) # добавить последнее поле в список
return fields
def escape_html(text):
text = text.replace("&", "&")
text = text.replace("<", "<")
text = text.replace(">", ">")
return text
if __name__ == '__main__':
main()