Careercup - Microsoft面试题 - 6543214668414976
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的更多相关文章
- Careercup - Microsoft面试题 - 6314866323226624
2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...
- Careercup - Microsoft面试题 - 6366101810184192
2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- Careercup - Microsoft面试题 - 5700293077499904
2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...
- Careercup - Microsoft面试题 - 5204967652589568
2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...
- Careercup - Microsoft面试题 - 5175246478901248
2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...
- Careercup - Microsoft面试题 - 5718181884723200
2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...
- Careercup - Microsoft面试题 - 5173689888800768
2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...
- Careercup - Microsoft面试题 - 6282862240202752
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...
随机推荐
- Eclipse 中打不开android sdk managerf
今天配置android sdk 的时候,出现了android sdk 打不开的情况.无论直接点击 sdk manager.exe 还是从eclipse启动,都不起作用,双重启(重启eclipse和ad ...
- 用AsyncTask 来实现下载图片在android开发中
Android使用AsyncTask 有如下好处: 1. 线程的开销较大,如果每个任务都要创建一个线程,那么应用程序的效率要低很多: 2. 线程无法管理,匿名线程创建并启动后就不受程序的控制了,如果有 ...
- 【风马一族_php】NO0_搭建web服务器
原文来自:http://www.cnblogs.com/sows/p/5977996.html (博客园的)风马一族 侵犯版本,后果自负 安装apache apache是一种B/S结构的软件,apa ...
- Arch 安装步骤
1.CFDISK 命令分区 一个主分区和一个逻辑分区 2.partprobe /dev/sdx 刷新分区表 3.mkfs 4. 5. 6.>dhcpcd 7. 8. 9. 10. 11. 12. ...
- C# 测试程序运行时间和cpu使用时间
方法一 Stopwatch类测试程序运行时间和cpu使用时间 添加命名空间using System.Diagnostics;使用实例如下 private Stopwatch sw = new Stop ...
- MongoDb gridfs-ngnix文件存储方案 - 图片
http://www.cnblogs.com/wintersun/p/4622205.html 在各类系统应用服务端开发中,我们经常会遇到文件存储的问题. 常见的磁盘文件系统,DBMS传统文件流存储. ...
- 【Window】Tor(洋葱头路由)+Privoxy 网络实践(附带Java实例代码)
1.背景 平时我们需要访问onion后缀的网站,需要通过Tor(The Onion Router,洋葱路由器).一般来说安装Tor Broswer就可以满足需要.但是项目我要做的是通过程序来获取oni ...
- QQ消息99+形成--第三方开源--BezierView
Android第三方开源的BezierView实现了上述QQ的99+条未读消息气泡显示.Android开源BezierView在github上的项目主页是:https://github.com/che ...
- How to get Financial Dimension Value from Worker Position[AX2012]
To get financial dimension value from worker position, add a new method in hcmWorker Table with scri ...
- build a git repo and clone
First machine: git init --bare gitrepo.git Second machine: git clone user@server:~/gitrepo.git cd gi ...