Skip to content

Instantly share code, notes, and snippets.

@eprislac
Last active February 22, 2019 08:52
Show Gist options
  • Save eprislac/48723fcba951e6387f5e3c421942e109 to your computer and use it in GitHub Desktop.
Save eprislac/48723fcba951e6387f5e3c421942e109 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <numeric>
using namespace std;
map<string, bool, greater<string>> fbMap(int num) {
map<string, bool, greater<string>> tbl;
tbl["Fizz"] = num % 3 == 0;
tbl["Buzz"] = num % 5 == 0;
return tbl;
}
vector<string> trueKeys(map<string, bool, greater<string>> myMap) {
vector<string> arr;
arr.reserve(2);
for(const auto & [key, val]: myMap) {
string item = val ? key : "";
arr.push_back(item);
}
return arr;
}
string trueKeysJoined(vector<string> arr) {
string retVal;
retVal = accumulate(arr.begin(), arr.end(), string(""));
return retVal;
}
string fizzbuzziness(int num) {
return trueKeysJoined(trueKeys(fbMap(num)));
}
int main() {
int num;
cout << "Please input a whole-number value:" << endl;
cin >> num;
cout << fizzbuzziness(num) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment