You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
497 B
27 lines
497 B
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
int main()
|
|
{
|
|
int n,a[10086];
|
|
cin>>n;
|
|
for(int i=0;i<n;i++)//输入
|
|
{
|
|
cin>>a[i];
|
|
}
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
for(int j=0;j<n-i+1;j++)//第二层循环的次数是关键 它决定进行几轮冒泡
|
|
{
|
|
if(a[j]<a[j+1])//如果前面的小于后面的
|
|
{
|
|
swap(a[j],a[j+1]);//交换两数位置
|
|
}
|
|
}
|
|
}
|
|
for(int i=0;i<n;i++)//输出
|
|
{
|
|
cout<<a[i]<<" ";
|
|
}
|
|
return 0;
|
|
}
|