fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <list>
  7. #include<ctime>
  8.  
  9. using namespace std;
  10.  
  11. class Point
  12. {
  13.  
  14. public:
  15. double x;
  16. double y;
  17.  
  18. bool operator<(Point &p)
  19. {
  20. if(x<p.x)
  21. return true;
  22. if(x==p.x)
  23. if(y<p.y)
  24. return true;
  25. else
  26. return false;
  27. if(x>p.x)
  28. return false;
  29. }
  30.  
  31. bool operator>(Point &p)
  32. {
  33. if(x>p.x)
  34. return true;
  35. if(x==p.x)
  36. if(y>p.y)
  37. return true;
  38. else
  39. return false;
  40. if(x>p.x)
  41. return false;
  42. }
  43.  
  44. };
  45.  
  46.  
  47. bool zakret(Point p1, Point p2, Point p3)
  48. {
  49. double wyznacznik=0.0;
  50. wyznacznik=(((p3.x-p1.x)*(p2.y-p1.y))-((p3.y-p2.y)*(p2.x-p1.x)));
  51. if(wyznacznik>0)
  52. return true;
  53. if(wyznacznik<0)
  54. return false;
  55. }
  56.  
  57.  
  58. int main()
  59. {
  60. srand(time(NULL));
  61. clock_t poczatek, koniec;
  62. double time;
  63. vector<Point> p;
  64.  
  65. int ile=0;
  66. cout<<"Ile punktow: "; cin>>ile;
  67. Point punkt1;
  68.  
  69. cout<<"\nPrzed sortowaniem"<<endl;
  70. for(int i=0; i<ile;i++)
  71. {
  72. punkt1.x=double(0.0+rand() % 1000);
  73. punkt1.y=double(0.0+rand() % 1000);
  74. // cout<<"Punkt "<<i<<": x="<<punkt1.x<<", y="<<punkt1.y<<endl;
  75. p.push_back(punkt1);
  76. }
  77.  
  78.  
  79.  
  80. poczatek=clock();
  81. sort(p.begin(),p.end());
  82. vector<Point> s1;
  83. vector<Point> s2;
  84. s1.push_back(p[0]);
  85. s1.push_back(p[1]);
  86.  
  87. cout<<"\nOtoczka gorna: ";
  88. for(int i=2; i<p.size();i++)
  89. {
  90. s1.push_back(p[i]);
  91. while(s1.size()>=2 && zakret(s1[s1.size()-2], s1[s1.size()-1], p[i])==0)
  92. {
  93. punkt1=s1[s1.size()-1];
  94. s1.pop_back();
  95. cout<<"x="<<punkt1.x<<", y="<<punkt1.y<<endl;
  96. }
  97. }
  98.  
  99.  
  100. s2.push_back(p[p.size()-1]);
  101. s2.push_back(p[p.size()-2]);
  102.  
  103. cout<<"\nOtoczna dolna: ";
  104. for(int i=p.size()-3; i>0 ;i--)
  105. {
  106. s2.push_back(p[i]);
  107. while(s2.size()>=2 && zakret(s2[s2.size()-2], s2[s2.size()-1], p[i])==0)
  108. {
  109. punkt1=s2[s2.size()-1];
  110. s2.pop_back();
  111. cout<<"x="<<punkt1.x<<", y="<<punkt1.y<<endl;
  112. }
  113. }
  114.  
  115. cout<<endl;
  116. koniec=clock();
  117. time=koniec-poczatek;
  118. cout<<"\n"<<endl;
  119. cout<<endl<<"Czas dzialania: "<<endl;
  120. cout<<"otoczka (metoda lancuchow): "<<time<<endl;
  121.  
  122. return 0;
  123. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
10
compilation info
prog.cpp: In member function ‘bool Point::operator<(Point&)’:
prog.cpp:22:11: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses]
prog.cpp: In member function ‘bool Point::operator>(Point&)’:
prog.cpp:35:11: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses]
prog.cpp: In function ‘int main()’:
prog.cpp:88:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h: In instantiation of ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; _Tp = Point]’:
/usr/include/c++/4.7/bits/stl_algo.h:2309:70:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >]’
/usr/include/c++/4.7/bits/stl_algo.h:2340:54:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; _Size = int]’
/usr/include/c++/4.7/bits/stl_algo.h:5476:4:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >]’
prog.cpp:81:23:   required from here
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: error: no match for ‘operator<’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<Point*, std::vector<Point> >() < __pivot’
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note: candidates are:
prog.cpp:18:10: note: bool Point::operator<(Point&)
prog.cpp:18:10: note:   no known conversion for argument 1 from ‘const Point’ to ‘Point&’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:65:0,
                 from /usr/include/c++/4.7/bits/char_traits.h:41,
                 from /usr/include/c++/4.7/ios:41,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/stl_pair.h:212:5: note: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.7/bits/stl_pair.h:212:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::pair<_T1, _T2>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
                 from /usr/include/c++/4.7/bits/char_traits.h:41,
                 from /usr/include/c++/4.7/ios:41,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator.h:299:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.7/bits/stl_iterator.h:299:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::reverse_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
                 from /usr/include/c++/4.7/bits/char_traits.h:41,
                 from /usr/include/c++/4.7/ios:41,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator.h:349:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.7/bits/stl_iterator.h:349:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::reverse_iterator<_IteratorL>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
                 from /usr/include/c++/4.7/bits/char_traits.h:41,
                 from /usr/include/c++/4.7/ios:41,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator.h:1057:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
/usr/include/c++/4.7/bits/stl_iterator.h:1057:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::move_iterator<_IteratorL>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
                 from /usr/include/c++/4.7/bits/char_traits.h:41,
                 from /usr/include/c++/4.7/ios:41,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator.h:1063:5: note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/usr/include/c++/4.7/bits/stl_iterator.h:1063:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::move_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/string:54:0,
                 from /usr/include/c++/4.7/bits/locale_classes.h:42,
                 from /usr/include/c++/4.7/bits/ios_base.h:43,
                 from /usr/include/c++/4.7/ios:43,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2566:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2566:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/include/c++/4.7/string:54:0,
                 from /usr/include/c++/4.7/bits/locale_classes.h:42,
                 from /usr/include/c++/4.7/bits/ios_base.h:43,
                 from /usr/include/c++/4.7/ios:43,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2578:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.7/bits/basic_string.h:2578:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/include/c++/4.7/string:54:0,
                 from /usr/include/c++/4.7/bits/locale_classes.h:42,
                 from /usr/include/c++/4.7/bits/ios_base.h:43,
                 from /usr/include/c++/4.7/ios:43,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2590:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2590:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   mismatched types ‘const _CharT*’ and ‘Point’
In file included from /usr/include/c++/4.7/vector:65:0,
                 from /usr/include/c++/4.7/bits/random.h:34,
                 from /usr/include/c++/4.7/random:50,
                 from /usr/include/c++/4.7/bits/stl_algo.h:67,
                 from /usr/include/c++/4.7/algorithm:63,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_vector.h:1387:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
/usr/include/c++/4.7/bits/stl_vector.h:1387:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::vector<_Tp, _Alloc>’
In file included from /usr/include/c++/4.7/functional:56:0,
                 from /usr/include/c++/4.7/bits/stl_algo.h:68,
                 from /usr/include/c++/4.7/algorithm:63,
                 from prog.cpp:3:
/usr/include/c++/4.7/tuple:808:5: note: template<class ... _TElements, class ... _UElements> bool std::operator<(const std::tuple<_TElements ...>&, const std::tuple<_Elements ...>&)
/usr/include/c++/4.7/tuple:808:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::tuple<_TElements ...>’
In file included from /usr/include/c++/4.7/list:64:0,
                 from prog.cpp:6:
/usr/include/c++/4.7/bits/stl_list.h:1603:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
/usr/include/c++/4.7/bits/stl_list.h:1603:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from prog.cpp:3:
/usr/include/c++/4.7/bits/stl_algo.h:2268:4: note:   ‘Point’ is not derived from ‘const std::list<_Tp, _Alloc>’
/usr/include/c++/4.7/bits/stl_algo.h:2271:4: error: passing ‘const Point’ as ‘this’ argument of ‘bool Point::operator<(Point&)’ discards qualifiers [-fpermissive]
prog.cpp: In member function ‘bool Point::operator<(Point&)’:
prog.cpp:29:5: warning: control reaches end of non-void function [-Wreturn-type]
prog.cpp: In function ‘bool zakret(Point, Point, Point)’:
prog.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
stdout
Standard output is empty