cpp study
来源:互联网 发布:java软件开发软件下载 编辑:程序博客网 时间:2024/05/17 08:09
#include <iostream>#include <iterator>#include <vector>#include <map>#include <list>#include <string>#include <algorithm>using namespace std;class Point{private:int x,y;public:Point(int x,int y):x(x),y(y){}double slopeTo(const Point& that) const{if (x == that.x && y == that.y) return - numeric_limits<double>::infinity();if (x == that.x) return numeric_limits<double>::infinity();if (y == that.y) return 0;return (that.y - y) / (double)(that.x - x);}bool operator< (const Point& that)const{if (y < that.y) return true;if (y == that.y && x < that.x) return true;return false;}friend ostream& operator<< (ostream&, Point& p);};class cmpBySlope{private:Point origin;public:cmpBySlope(Point& a) : origin(a){}bool operator() (const Point& left,const Point& right)const{return origin.slopeTo(left) < origin.slopeTo(right);}};ostream& operator<< (ostream& out, Point& p){cout << "(" << p.x << "," << p.y << ")" ;return out;}int N;vector<Point> v;void create(){cin >> N;for (int i = 0 ; i < N; i++){int x,y;cin >> x >> y;Point* p = new Point(x,y);v.push_back(*p);}cout << "Input reading has complete!" << endl;}int main(void) {create();cout << "Sort by natural order : ";sort(v.begin(),v.end());for (Point& p : v)cout << p << " ";cout << endl;cout << "Sort by slope : ";sort(v.begin(),v.end(),cmpBySlope(v[2]));for (Point& p : v){cout << p << " ";}cout << endl;}
0 0
- cpp study
- CPP Study
- Cpp.Study.Note.初识 Cpp中的类
- study
- study
- study
- study
- STUDY
- Study
- study
- study
- study...
- study
- study
- study
- study
- study
- study
- 学习Java程序制作Jar、exe和安装包过程中的问题记录及理解
- 设计模式(3) 工厂方法(Factory Mehod)
- java程序模拟页面发送http的post请求
- PHP Fckeditor上传文件(或图片)中文显示为乱码的解决方法
- csdn博文刷点击率测试,100%被封博客
- cpp study
- TODO
- 提高人生的档次
- POJ 2187 Beauty Contest
- android软件开发之webView.addJavascriptInterface循环渐进【一】
- 矩阵乘法
- 小小哲理
- C++类对象创建过程(分配空间、赋值和初始化、对象初始化顺序、虚函数表指针)
- python中三种处理文件输出的方式