Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
107451 | 梁敖铭 | 优化冒泡排序 | C++ | Accepted | 4 MS | 272 KB | 422 | 2025-01-17 20:43:32 |
#include<bits/stdc++.h> using namespace std; const int maxn =1e4 + 5; int a[maxn]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n - 1;++i){ bool flag = true; for(int j=1;j<=n - i;++j){ if(a[j]<a[j + 1]){ int t = a[j]; a[j] = a[j+1]; a[j+1]=t; flag = false; } } if(flag) break; } for(int i=1;i<=n;++i)cout<<a[i]<<" "; return 0; }