-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.cpp
More file actions
44 lines (36 loc) · 769 Bytes
/
FizzBuzz.cpp
File metadata and controls
44 lines (36 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> word;
string letter;
bool div_by_3;
bool div_by_5;
for (int i = 1; i <= n; ++i)
{
div_by_3 = i%3 == 0;
div_by_5 = i%5 == 0;
if (div_by_3 && div_by_5)
letter = "FizzBuzz";
else if (div_by_3)
letter = "Fizz";
else if (div_by_5)
letter = "Buzz";
else
letter = to_string(i);
word.push_back(letter);
}
return word;
}
};
int main(int argc, char const *argv[]) {
cout << "Main called!" << endl;
Solution sol;
vector<string> word = sol.fizzBuzz(15);
for (vector<string>::const_iterator i = word.begin(); i != word.end(); ++i)
cout << *i << endl;
return 0;
}