http://codeforces.com/problemset/problem/686/B
题意:
交换相邻的元素,使得序列从小到大排序。
思路:
模拟冒泡排序即可,数据范围不会超过 2W。点击查看:冒泡排序。
Code:
#include<cstdio>
#include<cstring>
const int MYDD=1103;
int main() {
int n;
while(scanf("%d",&n)!=EOF) {
int a[MYDD];
for(int j=1; j<=n; j++)
scanf("%d",&a[j]);
int num=0;
for(int j=1; j<=n; j++) {
for(int k=1; k<=n-j; k++) {
if(a[k]>a[k+1]) {
num++;
printf("%d %d\n",k,k+1);
int t=a[k+1];
a[k+1]=a[k];
a[k]=t;
}
}
}
}
return 0;
}
/* By:Shyazhut */