fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <utility>
  5. using namespace std;
  6.  
  7. bool sortPair (pair < int , int > &x , pair < int , int > &y)
  8. {
  9. if ( x.second % 2 == 0 && y.second % 2 == 0 && x.first == y.first )
  10. {
  11. if ( x.second > y.second )
  12. {
  13. return y.second < x.second ;
  14. }
  15. else
  16. {
  17. return x.second < y.second ;
  18. }
  19. }
  20.  
  21. if ( x.second % 2 != 0 && y.second != 0 && x.first == y.first )
  22. {
  23. if( x.second > y.second )
  24. {
  25. return y.second < x.second ;
  26. }
  27. else
  28. {
  29. return x.second < y.second ;
  30. }
  31. }
  32.  
  33. if ( x.second % 2 == 0 && y.second != 0 && x.first == y.first )
  34. {
  35. return y.second < x.second ;
  36. }
  37.  
  38. if ( x.second % 2 != 0 && y.second == 0 && x.first == y.first)
  39. {
  40. return x.second < y.second ;
  41. }
  42. }
  43.  
  44. int main()
  45. {
  46. int t = 1;
  47. while ( t -- )
  48. {
  49. int n , m , x;
  50. cin>> n >> m ;
  51. vector < pair < int , int > > u ;
  52.  
  53. for ( int i=0 ; i<n ; i++)
  54. {
  55. u.push_back(make_pair(x%m,x));
  56.  
  57. }
  58.  
  59. for ( int i=0 ; i<n ; i++)
  60. {
  61.  
  62. sort(u.begin(),u.end(),sortPair(u.at(i),u.at(i+1)));
  63.  
  64. }
  65.  
  66. cout<<endl;
  67. cout<<n<<" "<<m<<endl;
  68.  
  69. for (auto& e : u)
  70. {
  71. cout << e.first << "\n";
  72. }
  73. }
  74.  
  75. return 0;
  76. }
  77.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
15 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
compilation info
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = bool]':
/usr/include/c++/5/bits/stl_algo.h:1842:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:1880:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:1966:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:4729:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = bool]'
prog.cpp:62:63:   required from here
/usr/include/c++/5/bits/predefined_ops.h:123:46: error: expression cannot be used as a function
         { return bool(_M_comp(*__it1, *__it2)); }
                                              ^
/usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Value = std::pair<int, int>; _Compare = bool]':
/usr/include/c++/5/bits/stl_heap.h:129:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Distance = int; _Tp = std::pair<int, int>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool>]'
/usr/include/c++/5/bits/stl_heap.h:228:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Distance = int; _Tp = std::pair<int, int>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_heap.h:333:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:1669:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:1928:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:1943:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:1963:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/5/bits/stl_algo.h:4729:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = bool]'
prog.cpp:62:63:   required from here
/usr/include/c++/5/bits/predefined_ops.h:144:37: error: expression cannot be used as a function
  { return bool(_M_comp(*__it, __val)); }
                                     ^
stdout
Standard output is empty