|
|
back to boardwhat is my problem on c++? This is my code. #include <iostream> #include <vector> using namespace std; int main() { int n,a,k=0; cin>>n; vector <int> v; vector <int> sum; vector <int> index; for(int i=0; i<n; i++) { cin>>a; v.push_back(a); } for(int i=1; i<n-1; i++) { sum.push_back(v[i-1]+v[i]+v[i+1]); index.push_back(i); } int max=sum[0]; for(int i=1; i<n; i++) { if(sum[i]>max) {max=sum[i]; k=i;} } cout<<max<<" "<<index[k]+1; system("pause"); return 0; } Re: what is my problem on c++? If you look carefully, you don't get n sums and indexes, but actually n-2 sums and indexes. |
|
|