题目
Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
Example:
|
问题陈述:
太简单啦,略
题目思路:
遍历赋值,逢15、3、5的倍数赋值“FizzBuzz”,“Fizz”,“Buzz”,其余赋值为自然数顺序数
算法复杂度:O(n)
这里需要注意的是vector的push_back()函数复杂度为O(n),但是按下标随机访问的时间复杂度为O(1),所以用下标访问再赋值会比较快
代码:
|
结果