fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. class BizzElem{
  7. int N_;
  8. std::string Str_;
  9. bool Enable_;
  10. public:
  11. BizzElem(const int& Number, std::string Out, bool Enable = true) :N_(Number), Str_(Out), Enable_(Enable){};
  12.  
  13. bool Do(const int& i){
  14. if (Enable_ == false) return false;
  15. if (i == 0) return false;
  16. if (i%N_== 0){
  17. std::cout << Str_ << ',';
  18. return true;
  19. }
  20. return false;
  21. }
  22.  
  23. int N(){
  24. return N_;
  25. }
  26.  
  27. std::string String(){
  28. return Str_;
  29. }
  30.  
  31. bool IsEnable(){
  32. return Enable_;
  33. }
  34. bool ToMoveable(bool IsMove){
  35. Enable_ = IsMove;
  36. return Enable_;
  37. }
  38. };
  39.  
  40. class FizzBizz{
  41. std::vector<BizzElem> Vec_;
  42.  
  43. public:
  44.  
  45. FizzBizz(){};
  46.  
  47. bool Append(const BizzElem& BE){
  48. Vec_.push_back(BE);
  49. return true;
  50. }
  51.  
  52. bool operator ()(const int& N){
  53. bool F = false;
  54.  
  55. for (auto& o : Vec_){
  56. F |= o.Do(N);
  57. }
  58. if (F == true) std::cout<< std::endl;
  59. if (F == false) std::cout << N << std::endl;
  60.  
  61. return F;
  62. }
  63.  
  64. BizzElem& Find(std::string Name){
  65. static BizzElem NotFind(0, "NotFind!");
  66.  
  67.  
  68. for (auto& o : Vec_) if (o.String() == Name) return o;
  69.  
  70. return NotFind;
  71. }
  72.  
  73. };
  74.  
  75. int main(){
  76. FizzBizz FB;
  77.  
  78. FB.Append(BizzElem(3, "Fizz"));
  79. FB.Append(BizzElem(5, "Bizz"));
  80. FB.Append(BizzElem(7, "Gizz"));
  81. std::cout << 1 << ':';FB(1);
  82. std::cout << 3 << ':';FB(3);
  83. std::cout << 5 << ':';FB(5);
  84. std::cout << 7 << ':';FB(7);
  85. std::cout << 21 << ':';FB(21);
  86. std::cout << 35 << ':';FB(35);
  87. std::cout << 105 << ':';FB(105);
  88. std::swap(FB.Find("Gizz"), FB.Find("Bizz"));
  89. std::cout << 105 << ':';FB(105);
  90. std::swap(FB.Find("Gizz"), FB.Find("Bizz"));
  91. std::cout << 997 << ':';FB(997);
  92. std::cout << 999 << ':';FB(999);
  93.  
  94. std::cout << "------List Of 50------" << std::endl;
  95.  
  96. for (int i = 0; i < 50; i++) FB(i);
  97.  
  98.  
  99.  
  100. return 0;
  101. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
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,