杭电2019

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int a[110] = {0};//已经排好的
 7     int n,m;
 8     while (cin>>n>>m && n||m)
 9     {
10         a[0] = m;
11         for (int i = 1; i <= n; i++)
12         {
13             cin>> a[i];
14         }
15         for (int i =0; i<n; i++)
16         {
17             for (int j=0; j<n-i; j++)
18             {
19                 if (a[j+1]<a[j])
20                 {
21                     int tem;
22                     tem = a[j+1];
23                     a[j+1] = a[j];
24                     a[j] = tem;
25                 }
26             }
27         }
28         cout<< a[0];
29         for (int i =1;i<=n; i++)
30         {
31             cout<< ' '<< a[i];
32         }
33         cout<< endl;
34     }
35     return 0;
36 }

用冒泡排序,有待使用双数组倒换。

原文地址:https://www.cnblogs.com/lingc/p/3725476.html