Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Kanan Asgarli
- https://www.e-olymp.com/az/problems/1462
- */
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int n, a[100];
- int main()
- {
- //bubble sort
- cin>>n;
- for(int i = 0; i < n; i++)
- cin>>a[i];
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n-1; j++){
- if(a[j]%10 > a[j+1]%10){
- swap(a[j], a[j+1]);
- }
- if(a[j]%10 == a[j+1]%10 && a[j] > a[j+1]){
- swap(a[j], a[j+1]);
- }
- }
- }
- for(int i = 0; i < n; i++)
- cout<<a[i]<<" ";
- return 0;
- }
Add Comment
Please, Sign In to add comment