233
Ruby
code posted
by
233
created at 15 Dec 15:59
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#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; } } |
721 Bytes in 3 ms with coderay