fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. bool comp (const int& a, const int& b) {
  7. if (a % 10 == b % 10) return (a < b);
  8. else return a % 10 < b % 10;
  9. }
  10.  
  11. int main() {
  12. int n, a;
  13. vector<int> array;
  14. cin >> n;
  15. for (int i = 0; i < n; i++) {
  16. cin >> a;
  17. array.push_back(a);
  18. }
  19.  
  20. sort (array.begin(), array.end(), comp);
  21.  
  22. for (int a = 0; a < n; a++) {
  23. cout << array[a] << " ";
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 4452KB
stdin
10
82 22 19 90 34 17 588 921 200 121
stdout
90 200 121 921 22 82 34 17 588 19