pat 1104 Sum of Number Segments (20分) 测试点3需要long double
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805363914686464
模拟题,新改的测试数据需要long double型,如果测试点3无法通过,可以参考以下代码:
#include<bits/stdc++.h> using namespace std; int main() { int n; long double tmp,sum=0; cin>>n; for(int i=0;i<n;i++) { cin>>tmp; sum+=tmp*(n-i)*(i+1); } printf("%.2Lf\n",sum); return 0; }