看到一篇文章上说,很多貌似看过很多本编程书的童鞋连简单的fizz buzz测试都完不成.

不知道fizz buzz test为何物的,建议自行搜之.

测试要求是,编写满足以下条件的代码:

Write a program that prints the numbers from 1 to 100. But
 for multiples of three print “Fizz” instead of the number
 which are multiples of both three and five print
 “FizzBuzz”.

更通俗的说就是:

For each integer between 1 and 100, inclusive:
If the number is divisible by '3', then print "Fizz"
If the number is divisible by '5', then print "Buzz"
If the number is divisible by both '3' and '5', then print "FizzBuzz"
Otherwise, print the number.

本猫用Swift的解决方案如下:

for x in 1...100{
    if x % 3 == 0 && x % 5 == 0{
        print("FizzBuzz")
    }else if x % 3 == 0{
        print("Fizz")
    }else if x % 5 == 0{
        print("Buzz")
    }else{
        print(x)
    }
}

好吧,我承认是超级简单…我是有够无聊… ;[

Swift完成fizz buzz test的更多相关文章

  1. [Swift]LeetCode412. Fizz Buzz

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

  2. [LeetCode] Fizz Buzz 嘶嘶嗡嗡

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

  3. Lintcode 9.Fizz Buzz 问题

    ------------------------ AC代码: class Solution { /** * param n: As description. * return: A list of s ...

  4. LeetCode 412. Fizz Buzz

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

  5. LeetCode Fizz Buzz

    原题链接在这里:https://leetcode.com/problems/fizz-buzz/ 题目: Write a program that outputs the string represe ...

  6. Fizz Buzz

    class Solution { public: /** * param n: As description. * return: A list of strings. */ vector<st ...

  7. LintCode (9)Fizz Buzz

    下面是AC代码,C++风格: class Solution { public: vector<string> fizzBuzz(int N) { vector<string> ...

  8. [重构到模式-Chain of Responsibility Pattern]把Fizz Buzz招式重构到责任链模式

    写一段程序从1打印到100,但是遇到3的倍数时打印Fizz,遇到5的倍数时打印Buzz,遇到即是3的倍数同时也是5的倍数时打印FizzBuzz.例如: 1 2 Fizz 4 Buzz Fizz 7 8 ...

  9. Fizz Buzz 面试题

    在CSDN上看到一篇文章<软件工程师如何笑着活下去>,本来是想看对这个行业的一些评价和信息,不曾检索到关于Fizz Buzz的面试题,上网搜了一下,顿感兴趣.留下此文,以表回忆. java ...

随机推荐

  1. JavaScript初探之AJAX的应用

    什么是 AJAX1. AJAX = 异步 JavaScript 和 XML. 2. AJAX 是一种用于创建快速动态网页的技术. 3. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步 ...

  2. TCP三次握手详解及释放连接过程

    TCP在传输之前会进行三次沟通,一般称为"三次握手",传完数据断开的时候要进行四次沟通,一般称为"四次挥手". 两个序号和三个标志位: (1)序号:seq序号, ...

  3. [NOIp 2013]货车运输

    Description A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重 ...

  4. HDU3389 Game

    Problem Description Bob and Alice are playing a new game. There are n boxes which have been numbered ...

  5. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  6. 关于快速沃尔什变换(FWT)的一点学习和思考

    最近在学FWT,抽点时间出来把这个算法总结一下. 快速沃尔什变换(Fast Walsh-Hadamard Transform),简称FWT.是快速完成集合卷积运算的一种算法. 主要功能是求:,其中为集 ...

  7. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

  8. mysql 及 posgresql之优劣势大比拼

    特性 MySQL PostgreSQL 实例 通过执行 MySQL 命令(mysqld)启动实例.一个实例可以管理一个或多个数据库.一台服务器可以运行多个 mysqld 实例.一个实例管理器可以监视 ...

  9. 给div添加2个class

    <div class='center nocontent'>  类名用空格分开 在优先级一样的情况下就近原则  优先级# 100 .10 <span>这种标签是1 所以的相加 ...

  10. Python学习札记-eval函数

    eval()函数 eval()官方文档里面给出来的功能解释是:将字符串string对象转化为有效的表达式参与求值运算返回计算结果 语法上:调用的是:eval(expression,globals=No ...