E.cpp 516 B

1234567891011121314151617181920212223
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. for (unsigned n, x; cin >> n >> x;) {
  5. if (n == 0 and x == 0)break;
  6. vector<int> v(n);
  7. for (auto &e:v) {
  8. cin >> e;
  9. }
  10. v.emplace_back(x);
  11. for (int i = n - 1; i >= 0; i--) {//插入排序
  12. if (v[i] <= v[i + 1])
  13. break;
  14. swap(v[i], v[i + 1]);
  15. }
  16. for (auto &e:v) {
  17. cout << e << " ";
  18. }
  19. cout << endl;
  20. }
  21. return 0;
  22. }