SHARE
TWEET

2 H

kot_mapku3 Jun 2nd, 2020 534 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int sel(vector<int> v){
  7.     int s = 0;
  8.     for (int i = 0; i < v.size(); ++i) {
  9.         for (int j = i; j < v.size(); ++j) {
  10.             if (v[i] > v[j]) {
  11.                 swap(v[i],v[j]);
  12.                 s++;
  13.             }
  14.         }
  15.     }
  16.     return s;
  17. }
  18.  
  19. int main(){
  20.     ios::sync_with_stdio(false);
  21.     cin.tie(nullptr);
  22.  
  23.     int n; // полки
  24.     cin >> n;
  25.  
  26.     int b;
  27.     for (int i = 0; i < n; ++i) {
  28.         cin >> b;
  29.         vector<int> v(b);
  30.         for (int j = 0; j < b; ++j) {
  31.             cin >> v[j];
  32.         }
  33.         cout << sel(v) << "\n";
  34.     }
  35.  
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top