排序的题从来没有搞懂过
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 3001
struct node {
int s, e;
}edge[N];
int a[N];
int main() {
int n;
while(cin >> n) {
for(int i = 0; i < n; i ++)
cin >> a[i];
int k = 0;
for(int i = 0; i < n - 1; i ++) {
int Mi = a[i];
int mark = i;
for(int j = i + 1; j < n; j ++) {
if(a[j] < Mi) {
Mi = a[j];
mark = j;
}
}
if(mark != i) {
swap(a[i], a[mark]);
edge[k].s=i;
edge[k++].e=mark;
}
}
cout << k << endl;
for(int i = 0; i < k; i ++)
cout << edge[i].s << " " << edge[i].e << endl;
}
}
时间: 2024-10-14 04:00:54