回答編集履歴

1

加筆

2019/03/25 14:01

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -50,7 +50,45 @@
50
50
 
51
51
  std::cout << std::endl;
52
52
 
53
+ }
54
+
55
+ ```
56
+
57
+
58
+
59
+ [追記] 別解: 並列アルゴリズム版:
60
+
61
+ ```C++
62
+
63
+ #include <execution>
64
+
65
+ #include <algorithm>
66
+
67
+ #include <iostream>
68
+
69
+
70
+
71
+ int main() {
72
+
73
+ int a[] = { 1, 2, 3, 4 };
74
+
75
+ int b[] = { 2, 3, 4, 5 };
76
+
53
- return 0;
77
+ int ans[4];
78
+
79
+
80
+
81
+ std::transform(std::execution::par, a, a+4, b, ans, [](int x, int y) { return x+y;});
82
+
83
+
84
+
85
+ for (int i = 0; i < 4; i++) {
86
+
87
+ std::cout << ans[i] << ' ';
88
+
89
+ }
90
+
91
+ std::cout << std::endl;
54
92
 
55
93
  }
56
94