fork download
  1. class Solution {
  2. public: // solution by Abdrashim Eldan, any question: eldan.abdrashim@gmail.com
  3. vector<string> fizzBuzz(int n) { //If we look this method return vector <string>, it's say we work with vector;
  4. vector <string> res; // creat vector, we know vector its a dynamic array, that works with pointers and ampersands
  5. for(int i = 1; i <= n; i++){
  6. if(i % 15 == 0){ // first check: if i devided to 3 and 5 then we push in stack FizzBuzz
  7. res.push_back("FizzBuzz");
  8. }
  9. else if(i % 3 == 0){ // if i devided only to 3 then we push Fizz
  10. res.push_back("Fizz");
  11. }
  12. else if(i % 5 == 0){
  13. res.push_back("Buzz");
  14. }
  15. else{
  16. res.push_back(to_string(i)); // and the last one, if all the check not true, then we push i but convert to string;
  17. }
  18. }
  19. return res; // res, it's mean result.
  20. }
  21. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:5: error: 'vector' does not name a type
     vector<string> fizzBuzz(int n) { //If we look this method return vector <string>, it's say we work with vector;
     ^
stdout
Standard output is empty