NP100. 重载运算
描述
输入描述
输出描述
输出相加后的坐标。示例1
输入:
1 2 3 4
输出:
(4, 6)
Python 3 解法, 执行用时: 29ms, 内存消耗: 4516KB, 提交时间: 2022-07-31
class Coordinate(object): def __init__(self, x, y): self.x = x self.y = y def __str__(self): return '(%d, %d)'%(self.x, self.y) def __add__(self,other): return Coordinate(self.x+other.x, self.y+other.y) x1, y1 = list(map(int,input().split())) x2, y2 = list(map(int,input().split())) c1 = Coordinate(x1, y1) c2 = Coordinate(x2, y2) print(c1+c2)
Python 3 解法, 执行用时: 29ms, 内存消耗: 4520KB, 提交时间: 2022-07-30
class Coordinate(object): def __init__(self,x,y): self.x = x self.y = y def __str__(self): print(f"({self.x},{self.y})") def __add__(self,c): return self.x + c.x,self.y + c.y x1,y1 = map(int,input().split(' ')) x2,y2 = map(int,input().split(' ')) c1 = Coordinate(x1,y1) c2 = Coordinate(x2,y2) print(c1.__add__(c2))
Python 3 解法, 执行用时: 29ms, 内存消耗: 4528KB, 提交时间: 2022-08-04
class Coordinate: def __init__(self,x,y): self.x=x self.y=y def __str__(self): return "({}, {})".format(self.x,self.y) def __add__(self,other): self.x+=other.x self.y+=other.y return self x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) c1=Coordinate(x1,y1) c2=Coordinate(x2,y2) print(c1+c2)
Python 3 解法, 执行用时: 29ms, 内存消耗: 4544KB, 提交时间: 2022-08-04
class Coordinate: x = 0 y = 0 def __init__(self, x, y): self.x = x self.y = y def __str__(self): return '({}, {})'.format(self.x, self.y) def __add__(self, coord): return Coordinate(self.x + coord.x, self.y + coord.y) x1, y1 = input().split() x2, y2 = input().split() x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) c1 = Coordinate(x1, y1) c2 = Coordinate(x2, y2) print(c1 + c2)
Python 3 解法, 执行用时: 29ms, 内存消耗: 4548KB, 提交时间: 2022-08-02
class Coordinate(): def __init__(self, x, y): self.x = x self.y = y def __str__(self): return '(%d, %d)'%(self.x, self.y) def __add__(self, other): return Coordinate(self.x+other.x, self.y+other.y) x1, y1 = list(map(int,input().split())) x2, y2 = list(map(int,input().split())) c1 = Coordinate(x1, y1) c2 = Coordinate(x2, y2) print(c1+c2)