Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
100875 任斌 优化冒泡排序 C++ Accepted 5 MS 280 KB 411 2024-12-14 10:59:06

Tests(10/10):


Code:

#include<bits/stdc++.h> using namespace std; int main() { int a[2100]={0},n; int sum; bool k; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; k=false; } for(int i=0;i<n-1;i++){ for(int j=n-1;j>i;j--){ if(a[j]>a[j-1]){ sum=a[j]; a[j]=a[j-1]; a[j-1]=sum; k=true; } } if(k==false) break; } for(int i=0;i<n;i++){ cout<<a[i]<<" "; } return 0; }