Untitled
unknown
c_cpp
2 years ago
785 B
6
Indexable
#include<bits/stdc++.h> using namespace std; int main(){ int s,t,j=0,a[40]; while(cin>>s&&s){ a[j++]=s; } cin>>t; int b[40];//store addend while(t--){ memset(b,0,sizeof(b));//reset to 0 for(int now=0;now<j;now++){ if(now==0){ b[1]+=(a[now]>a[now+1] ? a[now]*0.1 : 0);//only 1 neighbor } else if(now==j-1){ b[now-1]+=(a[now]>a[now-1]?a[now]*0.1:0);//only 1 neighbor }else{ b[now-1]+=(a[now]>a[now-1]?a[now]*0.05:0);//left b[now+1]+=(a[now]>a[now+1]?a[now]*0.05:0);//right } } for(int i=0;i<j;i++) a[i]+=b[i];//add into a[i] } for(int i=0;i<j;i++) cout<<a[i]<<" "; }
Editor is loading...