-
-
Save Dobiasd/923ba25dac7c62eb6f5b432de6d7586b 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 <algorithm> | |
#include <iostream> | |
#include <map> | |
#include <numeric> | |
#include <string> | |
int main() | |
{ | |
typedef std::map<int, std::string> IntStringMap; | |
IntStringMap divisorsWithWords; | |
divisorsWithWords[3] = "Fizz"; | |
divisorsWithWords[5] = "Buzz"; | |
for(int i(1); i <= 100; ++i) | |
{ | |
std::string word = | |
std::accumulate(std::begin(divisorsWithWords), | |
std::end(divisorsWithWords), std::string(), | |
[&](const std::string& acc, | |
const IntStringMap::value_type& elem) | |
{ | |
if(i % elem.first == 0) | |
return acc + elem.second; | |
return acc; | |
}); | |
if(word.empty()) | |
word = std::to_string(i); | |
std::cout << word << ", "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment