asgarlikanan

https://www.e-olymp.com/az/problems/1462

Aug 19th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 0.50 KB | None | 0 0
  1. /*
  2.     Author: Kanan Asgarli
  3.     https://www.e-olymp.com/az/problems/1462
  4. */
  5. #include <iostream>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. int n, a[100];
  10. int main()
  11. {
  12.     //bubble sort
  13.     cin>>n;
  14.     for(int i = 0; i < n; i++)
  15.         cin>>a[i];
  16.     for(int i = 0; i < n; i++){
  17.         for(int j = 0; j < n-1; j++){
  18.             if(a[j]%10 > a[j+1]%10){
  19.                 swap(a[j], a[j+1]);
  20.             }
  21.             if(a[j]%10 == a[j+1]%10 && a[j] > a[j+1]){
  22.                 swap(a[j], a[j+1]);
  23.             }
  24.         }
  25.     }
  26.     for(int i = 0; i < n; i++)
  27.         cout<<a[i]<<" ";
  28.     return 0;
  29. }
Add Comment
Please, Sign In to add comment