hdoj 2019

来源:互联网 发布:dedelu.com最新域名 编辑:程序博客网 时间:2024/04/28 01:22
#include<iostream>
using namespace std;
int main(void)
{
    int n, x;
    while (cin >> n >> x && (n || x))
    {
        int *a = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++)
        {
            if (a[i] > x)
            {
                for (int j = n - 1; j >= i; j--)
                {
                    a[j + 1] = a[j];
                }
                a[i] = x;
                break;
            }
        }
        for (int j = 0; j <= n; j++)
        {
            if (j > 0) cout << " ";
            cout << a[j];
        }
        cout << endl;
        delete[]a;
    }
    return 0;
}
原创粉丝点击