fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. #include <algorithm>
  4. #include <vector>
  5. int m=2;
  6. bool cmp(int a,int b)
  7. {
  8. if(a%m<b%m)
  9. return true;
  10. if(a%m>b%m)
  11. return false;
  12. return a/m<b/m;
  13. }
  14. int main()
  15. {
  16. vector<int> arr;
  17. arr.push_back(4);arr.push_back(3);arr.push_back(2);arr.push_back(1);
  18. std::sort(arr.begin(),arr.end(),cmp);
  19. for(auto i:arr)
  20. cout<<i<<endl;
  21. // your code goes here
  22. return 0;
  23. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2
4
1
3