CF171C 【A Piece of Cake】

Compliance meaning of the questions enumeration violence
read people n, then find the $ \ sum ^ n_1a [i] * i $ then output the answer (remember to open a long long so as not to blow up)
Here is the code:

#include<bits/stdc++.h>
using namespace std;
long long n,a,sum;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		sum+=i*a;
	}
	cout<<sum<<endl;
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/20020219-liu/p/11609802.html