-
Notifications
You must be signed in to change notification settings - Fork 0
/
fizzbuzz.cpp
48 lines (36 loc) · 961 Bytes
/
fizzbuzz.cpp
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
45
46
47
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#if __cplusplus <= 201103L
#error This program needs at least a C++11 compliant compiler
#endif
void fizzbuzz( int64_t maxNumber)
{
auto generator = [=]() -> std::string
{
static int i = 1;
std::string ret;
if ( !( i%3 ) ) ret+="fizz";
if ( !( i%5 ) ) ret+="buzz";
++i;
return ret.empty() ? std::to_string(i-1) : ret ;
};
std::vector<std::string> a(maxNumber);
std::generate(a.begin(), a.end(),generator);
std::copy(a.begin(), a.end(), std::ostream_iterator<std::string>(std::cout,"\n"));
}
int main(int argc, char** argv)
{
if ( argc != 2 )
{
std::cerr <<"need one argument " << '\n';
return -1;
}
int64_t input = std::stoll(argv[1]);
std::cout <<"input : " << input <<'\n';
fizzbuzz(input);
return 0;
}