代码实现
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int item;
int data;
int a[10005] = { 0 };
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
cin >> item >> data;
int k = -1;
for (int i = 0; i < n; i++)
{
if (a[i] == item)
{
k = i;
n++;
}
}
if (k == -1)
{
a[n] = data;
n++;
}
else
{
for (int i = n; i >= k; i--)
{
a[i] = a[i - 1];
}
a[k] = data;
}
for (int i = 0; i < n-1; i++)
{
cout << a[i]<<" ";
}
cout << a[n-1] <<'\n';
return 0;
}