CCF 201809-1 卖菜
#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; }