From 2984d78e2078564c6e5d1e2db900cf8990d9c72b Mon Sep 17 00:00:00 2001 From: liuchuo <95323362@qq.com> Date: Thu, 18 Jun 2020 12:52:38 +0800 Subject: [PATCH] Update 1104. Sum of Number Segments (20).cpp --- AdvancedLevel_C++/1104. Sum of Number Segments (20).cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AdvancedLevel_C++/1104. Sum of Number Segments (20).cpp b/AdvancedLevel_C++/1104. Sum of Number Segments (20).cpp index 68141a0..ccd4ff6 100644 --- a/AdvancedLevel_C++/1104. Sum of Number Segments (20).cpp +++ b/AdvancedLevel_C++/1104. Sum of Number Segments (20).cpp @@ -3,11 +3,12 @@ using namespace std; int main() { int n; cin >> n; - double sum = 0.0, temp; + long long sum = 0; + double temp; for (int i = 1; i <= n; i++) { cin >> temp; - sum = sum + temp * i * (n - i + 1); + sum += (long long)(temp * 1000) * i * (n - i + 1); } - printf("%.2f", sum); + printf("%.2f", sum / 1000.0); return 0; } \ No newline at end of file