Пак Алиса, 611 группа SequenceDiv 796
Каплан Владимир Сергеевич 611 ВМК SequenceDiv 1275
f1import sysf1import sys
2import ast2import ast
33
n4class FloorDivTransformer(ast.NodeTransformer):n4class X(ast.NodeTransformer):
55
t6    def visit_BinOp(self, node):t6    def visit_BinOp(self, n):
7        self.generic_visit(node)7        self.generic_visit(n)
8        if isinstance(node.op, ast.FloorDiv):8        if isinstance(n.op, ast.FloorDiv):
9            return ast.copy_location(ast.Call(func=ast.Name(id='floor_di9            return ast.copy_location(ast.Call(func=ast.Name(id='y', ctx=
>v', ctx=ast.Load()), args=[node.left, node.right], keywords=[]), node)>ast.Load()), args=[n.left, n.right], keywords=[]), n)
10        return node10        return n
11input_code = sys.stdin.read()11i = sys.stdin.read()
12tree = ast.parse(input_code)12t = ast.parse(i)
13transformer = FloorDivTransformer()13x = X()
14tree = transformer.visit(tree)14t = x.visit(t)
15ast.fix_missing_locations(tree)15ast.fix_missing_locations(t)
16floor_div_code = '\ndef floor_div(a, b):\n    if isinstance(a, int):\n  16y_code = '\ndef y(a, b):\n    if isinstance(a, int):\n        return a /
>      return a // b\n    elif isinstance(a, (list, tuple, str)):\n      >/ b\n    elif isinstance(a, (list, tuple, str)):\n        return a[: len
>  return a[: len(a) // b]\n    else:\n        raise TypeError("Unsupport>(a) // b]\n'
>ed type for floor_div")\n' 
17floor_div_ast = ast.parse(floor_div_code)17y_ast = ast.parse(y_code)
18tree.body = floor_div_ast.body + tree.body18t.body = y_ast.body + t.body
19exec(compile(tree, filename='<ast>', mode='exec'))19exec(compile(t, filename='<ast>', mode='exec'))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op