-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFizzBuzz.cpp
49 lines (43 loc) · 862 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
48
49
//Tyler Witt
//CodeEval
//FizzBuzz.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
void fizzbuzz(string line);
int main(int argc, char *argv[]) {
ifstream stream(argv[1]);
string line;
while (getline(stream, line)) {
fizzbuzz(line);
cout << endl;
}
return 0;
}
void fizzbuzz(string line){
int limit;
int values[2];
bool flag;
for (int i = 0; i < 2; i++){
values[i] = atoi(line.substr(0, line.find(' ')).c_str());
line = line.substr(line.find(' ') + 1);
}
limit = atoi(line.c_str());
for (int i = 1; i <= limit; i++){
flag = false;
if (i % values[0] == 0){
cout << "F";
flag = true;
}
if (i % values[1] == 0){
cout << "B";
flag = true;
}
if (flag == false)
cout << i;
if (i < limit)
cout << ' ';
}
}