Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<string>
  8. #include<cstring>
  9. #include<vector>
  10.  
  11.  
  12. using namespace std;
  13.  
  14. void swap(int a, int b) {
  15.    
  16. }
  17.  
  18. int main() {
  19.     ios_base::sync_with_stdio(0);
  20.     cin.tie(0);
  21.     int a[5] = {2, 0, 1, 2, 0};
  22.     int b[5] = {-1, 7, 2, 3, 2};
  23.     int n =  5;
  24.  
  25.     for(int i=0; i<(n-1); i++)
  26.     {
  27.         for(int j=0; j<(n-i-1); j++)
  28.         {
  29.             int temp = 0;
  30.             if(a[j]>a[j+1])
  31.             {
  32.                 temp=a[j];
  33.                 a[j]=a[j+1];
  34.                 a[j+1]=temp;
  35.                 temp=b[j];
  36.                 b[j]=b[j+1];
  37.                 b[j+1]=temp;
  38.             }
  39.             if(a[j]==a[j+1]) {
  40.                 if (b[j] > b[j+1]) {
  41.                 temp=a[j];
  42.                 a[j]=a[j+1];
  43.                 a[j+1]=temp;
  44.                 temp=b[j];
  45.                 b[j]=b[j+1];
  46.                 b[j+1]=temp;
  47.                 }
  48.             }
  49.         }
  50.     }
  51.  
  52.  
  53. for (int i=0;i<n;i++) {
  54.     cout << a[i] << ' ' << b[i] << endl;
  55. }
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement