回答編集履歴
1
修正
test
CHANGED
@@ -18,15 +18,13 @@
|
|
18
18
|
|
19
19
|
std::tuple<double,double,double>
|
20
20
|
|
21
|
-
statistics(InputIterator first,
|
21
|
+
statistics(InputIterator first, size_t n) {
|
22
22
|
|
23
|
-
size_t n = std::distance(first, last);
|
24
|
-
|
25
|
-
double sum = std::accumulate(first,
|
23
|
+
double sum = std::accumulate(first, std::next(first,n), 0.0);
|
26
24
|
|
27
25
|
double mean = sum / n;
|
28
26
|
|
29
|
-
double stddev = sqrt(std::inner_product(first,
|
27
|
+
double stddev = sqrt(std::inner_product(first, std::next(first,n), first, 0.0)/n - mean*mean);
|
30
28
|
|
31
29
|
return { sum, mean, stddev };
|
32
30
|
|
@@ -48,11 +46,11 @@
|
|
48
46
|
|
49
47
|
using namespace std;
|
50
48
|
|
51
|
-
|
49
|
+
double input[] = { 0.01, 0.02, 0.03, 0.04, 0.05 };
|
52
50
|
|
53
51
|
double sum, mean, stddev;
|
54
52
|
|
55
|
-
tie(sum, mean,stddev) = statistics(
|
53
|
+
tie(sum, mean, stddev) = statistics(input, 5);
|
56
54
|
|
57
55
|
cout << "sum = " << sum << "\n"
|
58
56
|
|