[LeetCode]412 Fizz Buzz(水)
题目链接:https://leetcode.com/problems/fizz-buzz/?tab=Description
题意:被3整除被5整除XXX,同时XXX。
1 class Solution { 2 public: 3 vector<string> fizzBuzz(int n) { 4 vector<string> ret; 5 for(int i = 1; i <= n; i++) { 6 if(i % 3 == 0 && i % 5 == 0) ret.push_back("FizzBuzz"); 7 else if(i % 3 == 0) ret.push_back("Fizz"); 8 else if(i % 5 == 0) ret.push_back("Buzz"); 9 else { 10 char tmp[555]; 11 sprintf(tmp, "%d", i); 12 ret.push_back(tmp); 13 } 14 } 15 return ret; 16 } 17 };