回答編集履歴
1
加筆
answer
CHANGED
@@ -24,6 +24,25 @@
|
|
24
24
|
std::cout << ans[i] << ' ';
|
25
25
|
}
|
26
26
|
std::cout << std::endl;
|
27
|
-
return 0;
|
28
27
|
}
|
28
|
+
```
|
29
|
+
|
30
|
+
[追記] 別解: 並列アルゴリズム版:
|
31
|
+
```C++
|
32
|
+
#include <execution>
|
33
|
+
#include <algorithm>
|
34
|
+
#include <iostream>
|
35
|
+
|
36
|
+
int main() {
|
37
|
+
int a[] = { 1, 2, 3, 4 };
|
38
|
+
int b[] = { 2, 3, 4, 5 };
|
39
|
+
int ans[4];
|
40
|
+
|
41
|
+
std::transform(std::execution::par, a, a+4, b, ans, [](int x, int y) { return x+y;});
|
42
|
+
|
43
|
+
for (int i = 0; i < 4; i++) {
|
44
|
+
std::cout << ans[i] << ' ';
|
45
|
+
}
|
46
|
+
std::cout << std::endl;
|
47
|
+
}
|
29
48
|
```
|