2014-05-11 02:56

题目链接

原题:

Write a function called FooBar that takes input integer n and prints all the numbers from  upto n in a new line. If the number is divisible by  then print "Foo", if the number is divisible by  then print "Bar" and if the number is divisible by both  and , print "FooBar". Otherwise just print the number.
for example FooBar() should print as follows: Foo Bar
Foo Foo
Bar Foo FooBar I know, easy right? ;)

题目:从1到n的整数,如果被3整除就输出Foo,如果被5整除就输出Bar,如果是公倍数就输出FooBar,否则直接输出原数。

解法:这题有什么陷阱?n可以是大数吗?n可以小于1吗?如果是实际面试,肯定要问清楚的。在此,我就按最简单的处理了。在这种题目上自找麻烦是没意义的。

代码:

 // http://www.careercup.com/question?id=6543214668414976
#include <iostream>
#include <sstream>
using namespace std; int main()
{
int n;
int i; while (cin >> n && n > ) {
for (i = ; i <= n; ++i) {
if (i % ) {
if (i % ) {
cout << i;
} else {
cout << "Bar";
}
} else {
if (i % ) {
cout << "Foo";
} else {
cout << "FooBar";
}
}
cout << endl;
}
} return ;
}

Careercup - Microsoft面试题 - 6543214668414976的更多相关文章

  1. Careercup - Microsoft面试题 - 6314866323226624

    2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...

  2. Careercup - Microsoft面试题 - 6366101810184192

    2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...

  3. Careercup - Microsoft面试题 - 24308662

    2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...

  4. Careercup - Microsoft面试题 - 5700293077499904

    2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...

  5. Careercup - Microsoft面试题 - 5204967652589568

    2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...

  6. Careercup - Microsoft面试题 - 5175246478901248

    2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...

  7. Careercup - Microsoft面试题 - 5718181884723200

    2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...

  8. Careercup - Microsoft面试题 - 5173689888800768

    2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...

  9. Careercup - Microsoft面试题 - 6282862240202752

    2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...

随机推荐

  1. 著名的二分查找的BUG

    int binarySearch(int a[], int key, int length) { int low = 0; int high = length - 1; while (low < ...

  2. 搭建高性能计算环境(七)、应用软件的安装之MS

    1,上传软件包MaterialsStudio70.tgz.msi_7.lic到服务器上. 2,安装ms一般会创建一个普通用户msi,软件安装在msi账号下. 创建用户msi: useradd msi ...

  3. VBA删除表格最后一行

    Sub 删除最后一行() If MsgBox("要为所有表格添加列吗?", vbYesNo + vbQuestion) = vbYes Then To ActiveDocument ...

  4. JMeter2.13 连接 sql server

    1.安装驱动 http://www.microsoft.com/zh-CN/download/details.aspx?id=11774 下载最新的即可 解压后复制势穷力竭sqljdbc.jar到 “ ...

  5. 使用PyInstaller将Python程序打包成一个单独的exe文件

    1. 安装步骤略过 网上教程多 2. 用cmd进入PyInstaller的目录 然后执行以下命令: python pyinstaller.py -F C:\test.py 以上命令需要把Python目 ...

  6. C-链表的一些基本操作【创建-删除-打印-插入】

    #include <stdio.h> #include <stdlib.h> #include <malloc.h> #define LEN sizeof(stru ...

  7. Windos中无法删除桌面IE图标的解决方法

    解决方法其实并不难,打开注册表,转到如下图的位置,详细地址在图片最下面: 需要注意的是,你需要在NameSpace中逐个查看各个项目的数据值,显示为数据值为Internet Explorer的项目即为 ...

  8. 问题记录-Activity跳转后显示空白界面

    前两天写一个简易安卓记事本,从主界面跳转到添加内容界面总是显示空白. 明明有setContentView xml文件在可视化开发环境下也正常显示.后经前辈指点,原来是复写onCreate函数时出现了问 ...

  9. 信驰达携“Zigbee Light Link灯控方案”亮相第18届广州国际照明展

    2013年6月9日至12日,第18届广州国际照明展览会在琶洲中国进出口商品交易会展馆举行,作为全球照明及LED行业风向标和晴雨表,本次展会吸引了来自27个国际及地区,共2600多家企业参展.我公司受T ...

  10. ThinkPHP目录结构

    ThinkPHP框架目录结构 文件路径 文件描述 \index.php 入口文件 \Application 应用目录 \Public 资源文件目录 \ThinkPHP 框架核心目录   \Applic ...