由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个编程题
相关主题
写程序时的一个小问题?问个简单的atoi的问题
帮忙看看我写的atoi有没有bug, 谢谢问个算法题之被dynamic programming打败了
写了个atoi,大家帮看有没有哪里错了?问个linkedin题目
说个epic的机考题目EPIC online test: Additive number again
Linkedin 电面 面经x2问个offer 薪水的问题
fibonacci number问题问个面试题
分享一道trading firm的code screen,只能用c++问个BITWISE的题目。
长期帮忙推荐M家职位几道微软面试题
相关话题的讨论汇总
话题: fibonacci话题: n2话题: numbers话题: so话题: n1
进入JobHunting版参与讨论
1 (共1页)
P*******b
发帖数: 1001
1
Fibonacci Numbers: A number is said to be Fibonacci number if it follows the
fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not nec
essarily start with 1, as with the normal fibonacci series. So, in this new
definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and
so is 252550(25,25,50).
So, given any two numbers as input, print out all the Fibonacci Numbers with
in that range..
c**********e
发帖数: 2007
2

the
nec
new
and
with
Which range?

【在 P*******b 的大作中提到】
: Fibonacci Numbers: A number is said to be Fibonacci number if it follows the
: fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not nec
: essarily start with 1, as with the normal fibonacci series. So, in this new
: definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and
: so is 252550(25,25,50).
: So, given any two numbers as input, print out all the Fibonacci Numbers with
: in that range..

s*********t
发帖数: 1663
3
given (a,b)
for(i=1; ; i++){
//if "ii(i+i)" is larger than b, break
//else, find all fib numbers start with i, till it's larger than b, put
those larger than a into a set
}

the
nec
new
and
with

【在 P*******b 的大作中提到】
: Fibonacci Numbers: A number is said to be Fibonacci number if it follows the
: fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not nec
: essarily start with 1, as with the normal fibonacci series. So, in this new
: definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and
: so is 252550(25,25,50).
: So, given any two numbers as input, print out all the Fibonacci Numbers with
: in that range..

P*******b
发帖数: 1001
4
thanks

put

【在 s*********t 的大作中提到】
: given (a,b)
: for(i=1; ; i++){
: //if "ii(i+i)" is larger than b, break
: //else, find all fib numbers start with i, till it's larger than b, put
: those larger than a into a set
: }
:
: the
: nec
: new

I**A
发帖数: 2345
5
能不能详细说说?

【在 P*******b 的大作中提到】
: thanks
:
: put

s*********t
发帖数: 1663
6
我随便写了一个,凑合看下吧。。
std::set fibRange(int m, int n)
{
assert(m<=n);
std::set Set;
std::stringstream ss;
std::string s;
int n1,n2, tmp;
for(int i=1; ; i++){
n1 = i;
n2 = i+i;
ss.str("");
ss< s = ss.str();
if(atoi(s.c_str()) > n){
break;
}
while( atoi(s.c_str()) < m){
tmp = n1 + n2;
n1 = n2;
n2 = tmp;
ss< s = ss.str();

【在 I**A 的大作中提到】
: 能不能详细说说?
I**A
发帖数: 2345
7
没有特别看明白
你看我理解的对不对啊?
就是说
对每一个i, we will check whether ii(i+i)是不是在range内,在的话就放进去
然后看ii(i+i)(i+i+i)在不在range内,在的话就放进去,直到>range为止,再检查下
一个i。。。
这个题目所谓的fibnumber 必须是start with two same numbers?
ij(i+j)算不算?

【在 s*********t 的大作中提到】
: 我随便写了一个,凑合看下吧。。
: std::set fibRange(int m, int n)
: {
: assert(m<=n);
: std::set Set;
: std::stringstream ss;
: std::string s;
: int n1,n2, tmp;
: for(int i=1; ; i++){
: n1 = i;

s*********t
发帖数: 1663
8
那样就无穷无尽了

【在 I**A 的大作中提到】
: 没有特别看明白
: 你看我理解的对不对啊?
: 就是说
: 对每一个i, we will check whether ii(i+i)是不是在range内,在的话就放进去
: 然后看ii(i+i)(i+i+i)在不在range内,在的话就放进去,直到>range为止,再检查下
: 一个i。。。
: 这个题目所谓的fibnumber 必须是start with two same numbers?
: ij(i+j)算不算?

I**A
发帖数: 2345
9
哈哈哈,也是。。
不会无穷无尽的,有很多倒是真的。。
还有,直觉上觉得,因为有个start value参数
循环的时候,是不是不要从1开始更快些?
对于你的logic,我理解的没错?

【在 s*********t 的大作中提到】
: 那样就无穷无尽了
s*********t
发帖数: 1663
10
没错

【在 I**A 的大作中提到】
: 哈哈哈,也是。。
: 不会无穷无尽的,有很多倒是真的。。
: 还有,直觉上觉得,因为有个start value参数
: 循环的时候,是不是不要从1开始更快些?
: 对于你的logic,我理解的没错?

I**A
发帖数: 2345
11
thanks
我自己又想了一下
是要从1开始

【在 s*********t 的大作中提到】
: 没错
c********t
发帖数: 1756
12
while( atoi(s.c_str()) < m){
tmp = n1 + n2;
n1 = n2;
n2 = tmp;
ss< s = ss.str();
}
这段代码看不出来有啥用,是否可以去掉?
while( atoi(s.c_str()) <= n && atoi(s.c_str())>m )
即可.
s*********t
发帖数: 1663
13
如果开头几个数如果小于m则进不去循环了
改的话可以这样:
去掉前面的while(... 在while(... if( xxx > m ) xxx.insert(xxx)
即可

【在 c********t 的大作中提到】
: while( atoi(s.c_str()) < m){
: tmp = n1 + n2;
: n1 = n2;
: n2 = tmp;
: ss<: s = ss.str();
: }
: 这段代码看不出来有啥用,是否可以去掉?
: while( atoi(s.c_str()) <= n && atoi(s.c_str())>m )
: 即可.

x***y
发帖数: 633
14
what if the # of characters in b > the # of characaters in a? Then, even if
ii(i+i)> the first correponding characters in b, we can not eliminate it...

put

【在 s*********t 的大作中提到】
: given (a,b)
: for(i=1; ; i++){
: //if "ii(i+i)" is larger than b, break
: //else, find all fib numbers start with i, till it's larger than b, put
: those larger than a into a set
: }
:
: the
: nec
: new

1 (共1页)
进入JobHunting版参与讨论
相关主题
几道微软面试题Linkedin 电面 面经x2
一个答案看不明白谁解释一下fibonacci number问题
讨论:这个题怎么解分享一道trading firm的code screen,只能用c++
微软onsite面经--SDET长期帮忙推荐M家职位
写程序时的一个小问题?问个简单的atoi的问题
帮忙看看我写的atoi有没有bug, 谢谢问个算法题之被dynamic programming打败了
写了个atoi,大家帮看有没有哪里错了?问个linkedin题目
说个epic的机考题目EPIC online test: Additive number again
相关话题的讨论汇总
话题: fibonacci话题: n2话题: numbers话题: so话题: n1