1 C[ | ]
C
Copy
#include <stddef.h>
int *maps(const int *arr, size_t size) {
int *res = calloc(size, sizeof(int));
for(int i=0; i<size; i++) res[i] = arr[i]*2;
return res;
}
2 C++[ | ]
C++
Copy
std::vector<int> maps(const std::vector<int> & values) {
std::vector<int> res = values;
for(int& v: res) v *= 2;
return res;
}
C++
Copy
std::vector<int> maps(const std::vector<int> & values) {
std::vector <int> v = values;
std::transform(std::begin(v),std::end(v),std::begin(v),[](int x){return 2*x;});
return v;
}
C++
Copy
std::vector<int> maps(const std::vector<int> & values) {
std::vector<int> res;
for(auto a:values) res.push_back(a*2);
return res;
}
C++
Copy
std::vector<int> maps(const std::vector<int> & values) {
std::vector<int> res = values;
for(int& v: res) v *= 2;
return res;
}
3 Kotlin[ | ]
Kotlin
Copy
fun maps(x: IntArray): IntArray {
return x.map { it * 2 }.toIntArray()
}
Kotlin
Copy
fun maps(x : IntArray) = x.map { it * 2 }.toIntArray()
Kotlin
Copy
fun maps(x: IntArray): IntArray {
for (i in 0 until x.size) x[i] *= 2
return x
}
4 R[ | ]
R
Copy
maps <- function(v) {
v * 2
}
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.