-
Notifications
You must be signed in to change notification settings - Fork 1
/
FizzBuzz.cpp
48 lines (42 loc) · 1.09 KB
/
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
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
ifstream stream(argv[1]);
string line;
vector<string> split;
vector<string> nums;
int start;
int x, y, n;
while (getline(stream, line)){
split.clear();
start = 0;
for(int i = 0; i < line.length(); i++){
if(line[i] == ' ' || i == line.length()-1){
split.push_back(line.substr(start,i));
start = i+1;
}
}
x = stoi(split[0]);
y = stoi(split[1]);
n = stoi(split[2]);
nums.clear();
for(int i = 1; i <= n; i++){
if(i % x == 0 && i % y ==0){
nums.push_back("FB");
}else if(i % y == 0){
nums.push_back("B");
}else if(i % x == 0){
nums.push_back("F");
}else{
nums.push_back(to_string(i));
}
}
for(auto s : nums){
std::cout << s << " ";
}
std::cout << std::endl;
}
return 0;
}