#include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; int main() { int n; cin>>n; vector<int> a; for(int i=0;i<n;i++) { int temp; cin>>temp; a.push_back(temp); } int *b = (int *)malloc(sizeof(int)*n); for(int i=0;i<n;i++) { if(i==0) b[i]=(int)((a[i+1]+a[i])*1.0/2); else if(i==n-1) b[i]=(int)((a[i-1]+a[i])*1.0/2); else b[i]=(int)((a[i-1]+a[i+1]+a[i])*1.0/3); } for(int i=0;i<n;i++) { if(i==0) cout<<b[i]; else cout<<" "<<b[i]; } cout<<endl; }
原文:https://www.cnblogs.com/-Asurada-/p/14413459.html