[pat]1104. Sum of Number Segments (20)

https://www.patest.cn/contests/pat-a-practise/1104

tips:float会有case过不了

#include<iostream>
using namespace std;

int main(){
	int n;
	cin>>n;
	double sum = 0.0;
	for(int i = 0; i < n; i++){
		double a;
		cin>>a;
		sum += a * (i + 1) * (n - i);
	}
	printf("%.2f\n", sum);
	system("pause");
	return 0;
}


你可能感兴趣的:(pat,OJ)