Description
Input
Output
Sample Input
3 5.0 4.0 3.1 0.1 2.0 2.0 -1
Sample Output
3.1 0.1 5.0 4.0 2.0 2.0
#include<stdio.h> #include<algorithm> #include<string.h> #include<math.h> using namespace std; struct A { double x,y; double cos; }e[107]; int cmp(A a,A b) { return a.cos>b.cos; } int main() { int n; while (scanf("%d",&n)!=EOF) { int i; if(n<0) { break; } for(i=0;i<n;i++) { scanf("%lf%lf",&e[i].x,&e[i].y); e[i].cos=e[i].x/sqrt(e[i].x*e[i].x+e[i].y*e[i].y); } sort(e,e+n,cmp); for(i=0;i<n;i++) { printf("%.1f %.1f",e[i].x,e[i].y); if(i!=n-1) { printf(" "); } } printf("\n"); } return 0; } /*试了好多次,用g++提交就提示wrong answer,而使用c++提交就可以AC,到现在没搞懂到底是怎么回事。求知道什么原因的大神解答。*/
SDJZU_新生_排序_You Are All Excellent(sort方法)
原文地址:http://blog.csdn.net/floating_life/article/details/43155019