fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. int main()
  12. {
  13. ll k = 5;
  14. vector<ll> V {1,2,3,4,5,6,7,8,3,4,5,99,55,22,44,556,6};
  15. sort(V.begin(), V.end(), [k](ll a, ll b)
  16. {
  17. return (a%k == b%k) ? a < b : a%k < b%k;
  18. }
  19. );
  20.  
  21. for(auto i: V) cout << i << " ";
  22. }
  23.  
Success #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
5 5 55 1 6 6 556 2 7 22 3 3 8 4 4 44 99