412. Fizz Buzz

#include 
#include 
#include 

using namespace std;

class Solution {
public:
    vector fizzBuzz(int n) {
        vector output;
        for(int i = 1 ; i <= n ; i++)
            if(i % 3 == 0 && i % 5 == 0)
                output.push_back("FizzBuzz");
            else if(i % 3 == 0)
                output.push_back("Fizz");
            else if(i % 5 == 0)
                output.push_back("Buzz");
            else
                output.push_back(to_string(i));
        return output;
    }
};

int main(int argc, const char * argv[]) {
    Solution s ;
    int n;
    
    cin>>n;
    vector output = s.fizzBuzz(n);
    for(int i = 0 ; i < output.size() ; i++)
        cout<

你可能感兴趣的:(412. Fizz Buzz)