题目来源:http://www.lintcode.com/zh-cn/problem/fizz-buzz/
可以accept的程序如下:
class Solution {
public:
/**
* param n: As description.
* return: A list of strings.
*/
vector<string> fizzBuzz(int n) {
vector<string> results;
for (int i = ; i <= n; i++) {
if (i % == ) {
results.push_back("fizz buzz");
} else if (i % == ) {
results.push_back("buzz");
} else if (i % == ) {
results.push_back("fizz");
} else {
results.push_back(to_string(i));
}
}
return results;
}
};