标签:ons space menu std strong sub 统计 指定 输出
程序填空,产生指定输出结果
#include <iostream> #include <algorithm> #include <cmath> using namespace std; struct Point{ int x; int y; };
// 在此处补充你的代码
int main() { int a[8] = {6,5,55,23,3,9,87,10 }; sort(a,a+8,Rule1()); for(int i = 0;i < 8; ++i) cout << a[i] << "," ; cout << endl; Point ps[8] = {{1,0},{0,1},{0,-1},{-1,0},{1,-1},{1,1},{2,0},{-2,0} } ; sort(ps,ps+8,Rule2()); for(int i = 0;i < 8; ++i) cout << "(" << ps[i].x << "," << ps[i].y << ")"; return 0; }
无
10,23,3,55,5,6,87,9, (-1,0)(0,-1)(0,1)(1,0)(1,-1)(1,1)(-2,0)(2,0)
struct Rule1 { bool operator()(const int & a1,const int & a2) { if (a1%10==a2%10) return a1>a2; else return a1%10<a2%10; } }; struct Rule2 { bool operator()(const Point & ps1,const Point & ps2) { if ((ps1.x)*(ps1.x)+(ps1.y)*(ps1.y)==(ps2.x)*(ps2.x)+(ps2.y)*(ps2.y)) { if (ps1.x==ps2.x) return ps1.y<ps2.y; else return ps1.x<ps2.x; } else return ps1.x*ps1.x+ps1.y*ps1.y<ps2.x*ps2.x+ps2.y*ps2.y; } };
注意:
ps1,ps2的类型
标签:ons space menu std strong sub 统计 指定 输出
原文地址:http://www.cnblogs.com/w1992/p/7638427.html