题解 | #牛牛的平面向量#
牛牛的平面向量
https://www.nowcoder.com/practice/0e0d472d6a30469ab90d8b0aef7f81fe
#include <iostream> #include <vector> using namespace std; class Myvector { public: Myvector(int x, int y) { this->x = x; this->y = y; } int x; int y; Myvector operator+(Myvector& v) { Myvector v1(0,0); v1.x = this->x + v.x; v1.y = this->y + v.y; return v1; } void Myprint() { cout<<this->x<<" "<<this->y; } }; int main() { int n; cin >> n; Myvector v (0,0); for (int i = 0; i < n; i++) { int x; int y; cin >> x >> y; Myvector vi(x, y); v = v +vi; } v.Myprint(); return 0; }