[容易]Fizz Buzz 问题
题目来源:http://www.lintcode.com/zh-cn/problem/fizz-buzz/
可以accept的程序如下:
1 class Solution { 2 public: 3 /** 4 * param n: As description. 5 * return: A list of strings. 6 */ 7 vector<string> fizzBuzz(int n) { 8 vector<string> results; 9 for (int i = 1; i <= n; i++) { 10 if (i % 15 == 0) { 11 results.push_back("fizz buzz"); 12 } else if (i % 5 == 0) { 13 results.push_back("buzz"); 14 } else if (i % 3 == 0) { 15 results.push_back("fizz"); 16 } else { 17 results.push_back(to_string(i)); 18 } 19 } 20 return results; 21 } 22 };
-------------------------------------------------
原创博客 转载请注明出处http://www.cnblogs.com/hslzju
-------------------------------------------------
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步