64,651
社区成员
发帖
与我相关
我的任务
分享
#include"iostream"
#include"vector"
#include"string"
using namespace std;
class Solution {
public:
/**
* param n: As description.
* return: A list of strings.
*/
vector<string> fizzBuzz(int n) {
vector<string> results;
for (int i = 1; i <= n; i++) {
if (i % 15 == 0) {
results.push_back("fizz buzz");
}
else if (i % 5 == 0) {
results.push_back("buzz");
}
else if (i % 3 == 0) {
results.push_back("fizz");
}
else {
results.push_back(to_string(i));
}
}
return results;
}
};
void main(){
Solution t1;
vector<string> t2;
t2 = t1.fizzBuzz(15);
int i;
for (i = 0; i < 15;i++)
cout << t2[i] <<" " ;
cout << endl;
system("pause");
}