C语言运算符优先级等级口诀
2011-03-30 10:38
295 查看
在有关google的一道题目上已有不少人在讨论
其实,大家都被这道题目开了一道玩笑。。
原题:
Consider a function which, for a given whole number n, returns the number of ones required when writing out all numbers between 0 and n.
For example, f(13)=6. Notice that f(1)=1. What is the next largest n such that f(n)=n?
翻译过来大体是这样:
有一个整数n,写一个函数f(n),返回0到n之间出现的"1"的个数。比如f(13)=6,现在f(1)=1,问下一个最大的f(n)=n的n是什么?
为什么f(13)=6, 因为1,2,3,4,5,6,7,8,9,10,11,12,13.数数1的个数,正好是6.
题目是有极限的,而最大的数一般是溢出整型数的范围的。。
不过,google的题目目的就在开发考生的思维,所以答案开阔有很多思想。。
单单就f(n)的计算方法就很多,我想以此引出讨论,先看看有没有更一般的算法。。。
结果我会慢慢公布。。哈哈。。。有兴趣的多讨论。。。
其实,大家都被这道题目开了一道玩笑。。
原题:
Consider a function which, for a given whole number n, returns the number of ones required when writing out all numbers between 0 and n.
For example, f(13)=6. Notice that f(1)=1. What is the next largest n such that f(n)=n?
翻译过来大体是这样:
有一个整数n,写一个函数f(n),返回0到n之间出现的"1"的个数。比如f(13)=6,现在f(1)=1,问下一个最大的f(n)=n的n是什么?
为什么f(13)=6, 因为1,2,3,4,5,6,7,8,9,10,11,12,13.数数1的个数,正好是6.
题目是有极限的,而最大的数一般是溢出整型数的范围的。。
不过,google的题目目的就在开发考生的思维,所以答案开阔有很多思想。。
单单就f(n)的计算方法就很多,我想以此引出讨论,先看看有没有更一般的算法。。。
结果我会慢慢公布。。哈哈。。。有兴趣的多讨论。。。