#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* a = new int[n+1];
int* b = new int[n+1];
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
if (i == 1)
{
b[i] = (a[i] + a[i+1])/2;
}
else if (i == n)
{
b[n] = (a[n] + a[n - 1]) / 2;
}
else
{
b[i] = (a[i - 1] + a[i + 1] + a[i]) / 3;
}
}
for (int i = 1; i <= n; i++)
{
cout << b[i] << " ";
}
return 0;
}
第二个数组可以不用开的嘿嘿,不过内存给的够大,就不改了。
来源:CSDN
作者:▇ 楠墙
链接:https://blog.csdn.net/qq_44452887/article/details/104149579