aboutsummaryrefslogtreecommitdiffstats
path: root/412/main.cpp
blob: c0884ecc55ff9dd9cd2c54f38d16b18e6eb0e388 (plain) (blame)
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
#include "header.hpp"

class Solution {
public:
  static std::vector<std::string> fizzBuzz(int n) {
    std::vector<std::string> result;
    result.reserve(n);

    for (int i = 1; i <= n; ++i) {
      if (0 == i % 3) {
        if (0 == i % 5) [[unlikely]] {
          result.push_back("FizzBuzz");
        } else {
          result.push_back("Fizz");
        }
      } else if (0 == i % 5) {
        result.push_back("Buzz");
      } else [[likely]] {
        result.push_back(std::to_string(i));
      }
    }

    return result;
  }
};

int main(int argc, char **argv) {
  auto result = Solution::fizzBuzz(15);
  for (auto &iter : result) {
    std::cout << iter << ", ";
  }
  std::cout << "\n";
  return 0;
}