Created
August 10, 2020 16:25
-
-
Save c650/56583c7547d742f4fca9e0966f86bd87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
int main() { | |
std::vector<int> v{1,2,3,4}; | |
std::vector<int> b; | |
std::transform(v.begin(), v.end(), std::back_inserter(b), [](int a){return 2 * a;}); | |
auto it = std::remove_if(b.begin(), b.end(), [](int a){return a % 6 != 0;}); | |
b.erase(it, b.end()); | |
int res = std::accumulate(b.begin(), b.end(), 0); // by default, accumulate adds all the elements | |
std::cout << res << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment