# 测试 1035. 插入与归并(25)-pat乙级真题

guixianren · June 12, 2020 · 3 hits

### 输入例子:

10

3 1 2 8 7 5 9 4 6 0

1 2 3 7 8 5 9 4 6 0

### 输出例子:

Insertion Sort

1 2 3 5 7 8 9 4 6 0

## 解析

 `1234567891011121314151617181920212223242526272829303132` `#include // 要用到Sort函数，就要用到Algorithm 记住using namespace std;int (){ int n, a[100], b[100], i, j; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (i = 0; b[i] <= b[i + 1] && i < n - 1; i++); for (j = i + 1; a[j] == b[j] && j < n; j++); if (j == n){ cout << "Insertion Sort" << endl; sort(a, a + i + 2); } else { cout << "Merge Sort" << endl; int k = 1, flag = 1; while (flag){ flag = 0; for(i = 0; i < n; i++) if (a[i] != b[i]) flag = 1; k = k * 2; for (i = 0; i < n / k; i++) sort(a + i * k, a + (i + 1) * k); sort(a + n / k * k, a + n); } } for (i = 0; i < n - 1; i++) cout << a[i] << " "; cout << a[n - 1]; return 0; }`
No Reply at the moment.
You need to before reply, if you don't have an account, please first.