-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz.cpp
More file actions
64 lines (59 loc) · 1.7 KB
/
Copy pathfizzbuzz.cpp
File metadata and controls
64 lines (59 loc) · 1.7 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
cin>>n;
vector<string> answer;
//With MODULO OPERATOR
for(int i=1;i<=n;i++){
if(i%15==0){
answer.push_back("FizzBuzz");
}
else if(i%3==0){
answer.push_back("Fizz");
}
else if(i%5==0){
answer.push_back("Buzz");
}
else{
answer.push_back(to_string(i));
}
}
cout<<"[";
for(int j=0;j<=n;j++){
cout<<'"'<<answer[j]<<'"';
if(j<n){
cout<<",";
}
}
cout<<"]";
//without MODULO OPERATOR .... less complexity
// vector<string> ans;
// int count_three = 0, count_five = 0;
// for(int i = 1; i <= n; i++){
// count_three++;
// count_five++;
// if(count_three == 3 or count_five == 5){
// if(count_three == 3 and count_five == 5){
// ans.push_back("FizzBuzz");
// count_three = 0;
// count_five = 0;
// continue;
// }else {
// if(count_three == 3){
// ans.push_back("Fizz");
// count_three = 0;
// }
// if(count_five == 5){
// ans.push_back("Buzz");
// count_five = 0;
// }
// }
// continue;
// }else {
// ans.push_back(to_string(i));
// }
// }
}