fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin >> n;
  8. int mass[n];
  9. for (int i = 0; i < n; i++) {
  10. cin >> mass[i];
  11. }
  12.  
  13. for (int i = 0; i < n; i++){
  14. for (int j = 1; j < (n - i); j++) {
  15. if (mass[j] % 10 < mass[j-1] % 10) {
  16. swap (mass[j-1], mass[j]);
  17. }
  18. else if ( mass[j] % 10 == mass[j-1] % 10 and mass[j] < mass[j-1]){
  19. swap (mass[j-1], mass[j]);
  20. }
  21. }
  22. }
  23.  
  24. for (int i = 0; i < n; i++) {
  25. cout << mass[i] << " ";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 4348KB
stdin
9
78 33 13 0 12 89 20 78 9990	
stdout
0 20 9990 12 13 33 78 78 89