Title / Description
Code #include <iostream> #include <algorithm> #include <vector> #include <cstdio> using namespace std; int n, a[5005], b, c, d, e; vector <pair<int, int> > vec; int main(){ cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i < n; i ++){ int mn = 1e9 + 7, pos = -1; for(int j = i + 1; j <= n; j ++) if(mn > a[j]){ mn = a[j], pos = j; } if(mn < a[i]){ swap(a[i], a[pos]); vec.push_back(make_pair(i, pos)); } } cout << vec.size() << endl; for(int i = 0; i < vec.size(); i ++){ cout << vec[i].first - 1 << ' ' << vec[i].second - 1 << endl; } }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code