Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream f("sortareunghi.in");
- ofstream g("sortareunghi.out");
- pair<int,int> v[101];
- int n,i;
- int cadran(int x,int y)
- {
- if(x>0&&y>=0)
- return 1;
- if(x<=0&&y>0)
- return 2;
- if(x<=0&&y<=0)
- return 3;
- return 4;
- }
- int det(int X1,int Y1,int X2,int Y2,int X3,int Y3)
- {
- return (X2-X1)*(Y3-Y1)-(X3-X1)*(Y2-Y1);
- }
- int cmp(const pair<int,int> &a,const pair<int,int> &b)
- {
- int c1=cadran(a.first,a.second);
- int c2=cadran(b.first,b.second);
- if(c1!=c2)
- return c1<c2;
- else
- {
- int d=det(0,0,a.first,a.second,b.first,b.second);
- if (d!=0)
- return d>0;
- else
- return a.first*a.first+a.second*a.second<b.first*b.first+b.second*b.second;
- }
- }
- int main()
- {
- f>>n;
- for (i=1;i<=n;++i)
- f>>v[i].first>>v[i].second;
- sort(v+1,v+n+1,cmp);
- for (i=1;i<=n;++i)
- g<<v[i].first<<' '<<v[i].second<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement