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:
n = 15,
Return:
[
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz"
]

vector<string> fizzBuzz(int n){vector<string>ret;stringstream ss;if (n < 1) return ret;for (int i = 1; i <= n;i++){ss << i;if (i%3 ==0 && i%5!=0) ret.push_back("Fizz");            else if (i%5 ==0 && i%3!=0) ret.push_back("Buzz");             else if (i%15==0) ret.push_back("FizzBuzz");else ret.push_back(ss.str());ss.str("");             }return ret;}

转载于:https://www.cnblogs.com/hellowooorld/p/6842297.html

[leetcode-412-Fizz Buzz]相关推荐

  1. leetcode 412. Fizz Buzz

    Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...

  2. 【leetcode】412.Fizz Buzz (三种方法开阔思路,java实现)

    412. Fizz Buzz 难度简单 写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz ...

  3. 【快乐水题】412. Fizz Buzz

    原题: 力扣链接:412. Fizz Buzz 题目简述: 给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果,其中 ...

  4. 【跟Leon一起刷LeetCode】412. Fizz Buzz

    Fizz Buzz Description: Write a program that outputs the string representation of numbers from 1 to n ...

  5. LeetCode 1195. Fizz Buzz Multithreaded--并发系列题目--Java 解法--AtomicInteger/CountDownLatch/CyclicBarrier

    题目地址:Fizz Buzz Multithreaded - LeetCode Write a program that outputs the string representation of nu ...

  6. 412. Fizz Buzz(java)

    写一个程序,输出从 1 到 n 数字的字符串表示.1. 如果 n 是3的倍数,输出"Fizz":2. 如果 n 是5的倍数,输出"Buzz":3.如果 n 同时 ...

  7. LeetCode之Fizz Buzz

    1.题目 Write a program that outputs the string representation of numbers from 1 to n. But for multiple ...

  8. 412. Fizz Buzz

    Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...

  9. Java/412.Fizz Buzz

    题目 代码部分(2ms 98.26%) class Solution {public List<String> fizzBuzz(int n) {List<String> re ...

  10. LeetCode412_412. Fizz Buzz

    LeetCode412_412. Fizz Buzz 一.描述 给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果, ...

最新文章

  1. linux磁盘怎么分区比较好,500G的硬盘,怎么分区比较合理?
  2. 【数据平台】Eclipse+Scala开发环境(本机和集群两个运行模式)
  3. ddr4 lpddr4区别_iFixit 拆解 iPhone 12 系列:仍使用 LPDDR4 内存 | 爱搞机
  4. $.when.apply_When2Meet vs.LettuceMeet:UI和美学方面的案例研究
  5. operation 多线程
  6. linux c read函数返回值,Linuxc - GNU Readline 库及编程简介
  7. 余额宝存5万2千,为什么每天只有3.6元?
  8. Flutter 本地小说阅读器
  9. matlab 生命游戏
  10. Yii2.0 获取当前url和域名
  11. 周鸿祎谈产品:像怀胎一样怀产品,要厚着脸皮听批评
  12. 征服spring源码(一)
  13. 志愿者招募| WasmEdge 邀你参加第七届中国开源年会 COSCon 2022
  14. 计算机专业相关的组名和口号,好的小组队名和口号(精选40个)
  15. classes是什么意思怎么读_class是什么意思_class怎么读_class翻译_用法_发音_词组_同反义词_班-新东方在线英语词典...
  16. 非功能性需求基础概念
  17. 微信公众号支付宝授权
  18. android多线程下载程序卡死,android 多线程下载与断点续传
  19. 计算方法(二):n次多项式插值
  20. .NET 7 预览版 7

热门文章

  1. tomcat基本使用和超图基本jsp例子
  2. 8086汇编语言显示带颜色的字符串程序学习 - 使用emu8086
  3. 超图js版本加载点图层和点要素
  4. 图解LanHelper 使用
  5. jquery.desktop.js 代码分析
  6. OO Unit4 UML
  7. Vue(小案例_vue+axios仿手机app)_实现用户评论
  8. Go语言的DES加密(CBC模式, ECB模式) ---- 与java加密互通(转)
  9. HTML td 标签的 colspan 属性
  10. POJ 1821 Fence ★(单调队列优化DP)