Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
101394 刘轻松 优化冒泡排序 C++ Accepted 5 MS 280 KB 500 2024-12-15 10:47:23

Tests(10/10):


Code:

//冒泡排序 #include<bits/stdc++.h> using namespace std; const int MAXN=2000; //定义常量 int a[MAXN]; int main(){ int n,t,k=0; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } //冒泡排序 for(int i=0;i<n-1;i++) //排序的轮数 { for(int j=0;j<n-1-i;j++){ //每轮排序的下标取值 if(a[j]<a[j+1]){ swap(a[j],a[j+1]); //交换 } } } //输出结果 for(int i=0;i<n-1;i++){ cout<<a[i]<<" "; } cout<<a[n-1]; return 0; }