zoukankan      html  css  js  c++  java
  • 二位几何运算类

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <vector>
     4 #include <iostream>
     5 #include <algorithm>
     6 #include <set>
     7 #include <map>
     8 #include <queue>
     9 #include <cmath>
    10 
    11 using namespace std;
    12 struct Point
    13 {
    14     int x,y;
    15     Point(int x = 0,int y = 0): x(x),y(y) {}
    16     Point operator = (Point p) {x = p.x;y = p.y;return *this;}
    17 };
    18 
    19 Point operator + (const Point& A,const Point& B){return Point(A.x+B.x,A.y+B.y);}
    20 Point operator - (const Point& A,const Point& B){return Point(A.x-B.x,A.y-B.y);}
    21 Point operator * (const Point& A,int p){return Point(A.x*p,A.y*p);}
    22 bool operator == (const Point& A,const Point &B) {return A.x==B.x && A.y == B.y;}
    23 bool operator < (const Point& p1,const Point& p2) {return p1.x < p2.x || (p1.x==p2.x && p1.y < p2.y);}
    24 istream & operator >> (istream& is,Point& p) {return is >> p.x >> p.y;}
    25 ostream & operator << (ostream& os,Point& p) {return os << p.x << " " << p.y;}
    26 int main()
    27 {
    28     Point p1(3,4),p2(7,8);
    29     if(p1<p2)
    30         cout << "p1 is smaller than p2" << endl;
    31     Point p3 = p1 + p2;
    32     cout << p3 << endl;
    33     Point p4;
    34     cin >> p4;
    35     cout << p4 << endl;
    36     p4 = p3*3;
    37     cout << p4 << endl;
    38     return 0;
    39 }
  • 相关阅读:
    python条件判断之直接加数字
    pythontip题目解答
    twitter api取出的日期格式化
    MySQL Archive存储引擎
    Python Json序列化
    Python 装饰器
    Python 匿名函数
    Python 函数
    Python 字符编码
    Python 文件操作
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9729353.html
Copyright © 2011-2022 走看看