nacuole

null him 2020-09-03 21:34:39 2020-09-04 19:45:44 8
#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;
}
{{ vote && vote.total.up }}

共 5 条回复

ykj11

#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] << " "; }

root 站长

hh~

chen_zhe 沙雕

sort(a + 1, a + n + 1)功能是将a[1]a[n]从小到大排序。

chen_zhe 沙雕

真·冒泡排序·会超时

chen_zhe 沙雕

将代码全选按TAB全文换行

就像这样:

    #include <iostream>

换行后代码就不会乱了