#include <iostream> #include <string> #include <vector> #include <algorithm> class BizzElem{ int N_; std::string Str_; bool Enable_; public: BizzElem(const int& Number, std::string Out, bool Enable = true) :N_(Number), Str_(Out), Enable_(Enable){}; bool Do(const int& i){ if (Enable_ == false) return false; if (i == 0) return false; if (i%N_== 0){ std::cout << Str_ << ','; return true; } return false; } int N(){ return N_; } std::string String(){ return Str_; } bool IsEnable(){ return Enable_; } bool ToMoveable(bool IsMove){ Enable_ = IsMove; return Enable_; } }; class FizzBizz{ std::vector<BizzElem> Vec_; public: FizzBizz(){}; bool Append(const BizzElem& BE){ Vec_.push_back(BE); return true; } bool operator ()(const int& N){ bool F = false; for (auto& o : Vec_){ F |= o.Do(N); } if (F == true) std::cout<< std::endl; if (F == false) std::cout << N << std::endl; return F; } BizzElem& Find(std::string Name){ static BizzElem NotFind(0, "NotFind!"); for (auto& o : Vec_) if (o.String() == Name) return o; return NotFind; } }; int main(){ FizzBizz FB; FB.Append(BizzElem(3, "Fizz")); FB.Append(BizzElem(5, "Bizz")); FB.Append(BizzElem(7, "Gizz")); std::cout << 1 << ':';FB(1); std::cout << 3 << ':';FB(3); std::cout << 5 << ':';FB(5); std::cout << 7 << ':';FB(7); std::cout << 21 << ':';FB(21); std::cout << 35 << ':';FB(35); std::cout << 105 << ':';FB(105); std::swap(FB.Find("Gizz"), FB.Find("Bizz")); std::cout << 105 << ':';FB(105); std::swap(FB.Find("Gizz"), FB.Find("Bizz")); std::cout << 997 << ':';FB(997); std::cout << 999 << ':';FB(999); std::cout << "------List Of 50------" << std::endl; for (int i = 0; i < 50; i++) FB(i); return 0; }
Standard input is empty
1:1 3:Fizz, 5:Bizz, 7:Gizz, 21:Fizz,Gizz, 35:Bizz,Gizz, 105:Fizz,Bizz,Gizz, 105:Fizz,Gizz,Bizz, 997:997 999:Fizz, ------List Of 50------ 0 1 2 Fizz, 4 Bizz, Fizz, Gizz, 8 Fizz, Bizz, 11 Fizz, 13 Gizz, Fizz,Bizz, 16 17 Fizz, 19 Bizz, Fizz,Gizz, 22 23 Fizz, Bizz, 26 Fizz, Gizz, 29 Fizz,Bizz, 31 32 Fizz, 34 Bizz,Gizz, Fizz, 37 38 Fizz, Bizz, 41 Fizz,Gizz, 43 44 Fizz,Bizz, 46 47 Fizz, Gizz,