看到一篇文章上说,很多貌似看过很多本编程书的童鞋连简单的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. ABP框架 - N层架构

    目录 介绍 DDD分层 ABP架构模型 客户端 展现层 分布式服务层 应用层 领域层 基础设施层 介绍 在应用程序设计中,分层架构是一种被广泛使用的技术,它助于降低复杂度和提高代码的可重用性.在ABP ...

  2. Genymotion下载慢或者下载失败的解决办法

    转.原文地址:http://blog.csdn.net/sean_css/article/details/52674091 办法如下: 1.首先点击界面上的 + 号(Add)按钮,选择你要下载的模拟器 ...

  3. 树莓派控制HC-SR04超声波模块测距(新手向+C语言向)

    因为作业要求使用c语言代码,这里先附上一段摘自网上的代码 感谢KalaerSun的c语言代码,摘自https://blog.csdn.net/qq_25247589/article/details/6 ...

  4. [SCOI 2012]滑雪与时间胶囊

    Description a180285非常喜欢滑雪.他来到一座雪山,这里分布着M条供滑行的轨道和N个轨道之间的交点(同时也是景点),而且每个景点都有一编号i(1<=i<=N)和一高度Hi. ...

  5. UVA1349:Optimal Bus Route Design

    题意:给定一个有向带权图,找若干个环,使得每个点属于且仅属于一个环,要求使得环权值之和最小 题解:发现这题中每个点属于且仅属于一个环,这时候"仅"这种恰好的含义,让我们想到了匹配问 ...

  6. 网络编程基础API

    1.预备知识 网络字节序 1.TCP/IP协议规定,网络数据流应采用大端字节序 0x12345678 小端存储:78存储在低地址 大端存储:12存储在低地址 网络字节序和主机字节序的转换 #inclu ...

  7. Codeforces 671 D. Roads in Yusland

    题目描述 Mayor of Yusland just won the lottery and decided to spent money on something good for town. Fo ...

  8. xx学院学员评优评奖管理系统

    [勤拂拭软件,软件开发,毕业设计,程序作业,论文写作指导:q-[1215714557]  加好友请注明:勤拂拭)] 之前帮助一个军校学生做的一个评优评奖管理系统,该系统主要用于学校学生评优评先使用. ...

  9. Python中模块之collections系列

    collection系列功能介绍 1. 常用的集中类 1. Counter(计数器) 计数器的常用方法如下: 创建一个字典计数器 格式:collections.Counter(obj) 例如:prin ...

  10. dev gridcontrol 无法编辑 解决方案

    1.确认表格打开编辑 gridView1.OptionsBehavior.Editable = True 2.确认列打开编辑 gridView1.Columns("Name").O ...