这是什么排序?
  • 板块灌水区
  • 楼主sy_dudu
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/12/8 10:55
  • 上次更新2024/12/8 13:58:35
查看原帖
这是什么排序?
1388786
sy_dudu楼主2024/12/8 10:55

题目:P1116,可以AC

#include<iostream>
using namespace std;
int bub(int *st,int len){
	int cnt=0;
	for(int i=0;i<len;i++){
		for(int j=0;j<i;j++){
			if(st[i]<st[j]){
				swap(st[i],st[j]);
				++cnt;
			}
		}
	}
	return cnt;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int a;
	cin>>a;
	int b[a];
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	cout<<bub(b,a)<<'\n';
	for(int i=0;i<a;i++){
		cout<<b[i]<<' ';
	}
	return 0;
}
2024/12/8 10:55
加载中...