#include<iostream>
#include<cstdio>
using namespace std;
float a[5000005];
int main(){
float temp;
long long int i,j,n;
cin>>n;
for(i=1;i<=n;i++){
cin>>a[i];
}
for(i=1;i<=n-1;i++){
for(j=1;j<=n-i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=1;i<=n;i++){
cout<<a[i]<<" ";
}
return 0;
}
共 5 条回复
#include <bits/stdc++.h> using namespace std; const int N = 1005000; int a[N]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) cout << a[i] << " "; }
hh~
sort(a + 1, a + n + 1)功能是将
a[1]
a[n]
从小到大排序。真·冒泡排序·会超时
将代码全选按TAB全文换行
就像这样:
换行后代码就不会乱了