2014年4月23日

摘要: Question:The sum of the squares of the first ten natural numbers is,12+ 22+ ... + 102= 385The square of the sum of the first ten natural numbers is,(1... 阅读全文
posted @ 2014-04-23 19:32 楠哥1991 阅读(87) 评论(0) 推荐(0) 编辑
摘要: Question:2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive numbe... 阅读全文
posted @ 2014-04-23 19:29 楠哥1991 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Question:A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 9199.Find the la... 阅读全文
posted @ 2014-04-23 17:22 楠哥1991 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Question:The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?C Code:void main(){ int prim[20... 阅读全文
posted @ 2014-04-23 17:18 楠哥1991 阅读(112) 评论(0) 推荐(0) 编辑
摘要: Question:Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:1... 阅读全文
posted @ 2014-04-23 17:14 楠哥1991 阅读(96) 评论(0) 推荐(0) 编辑
摘要: Question:If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum... 阅读全文
posted @ 2014-04-23 17:12 楠哥1991 阅读(108) 评论(0) 推荐(0) 编辑

2014年3月1日

摘要: 平时在使用不同类型进行比较或者运算时,如果我们不进行显示类型转化时,编译器都会进行隐式转换,但是隐式转换往往会带来一下注意不到的错误点,下面就是一例:#include#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))int array[] = {23,34,12,17,204,99,16};int main(){ int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]); return 0; }程序的愿意图是为了输出int 阅读全文
posted @ 2014-03-01 21:55 楠哥1991 阅读(1052) 评论(0) 推荐(0) 编辑

2014年2月21日

摘要: 好像是一道微软的面试题:已知两个1~30之间的数字,甲知道两数之和,乙知道两数之积。 甲问乙:"你知道是哪两个数吗?"乙说:"不知道"; 乙问甲:"你知道是哪两个数吗?"甲说:"也不知道"; 于是,乙说:"那我知道了"; 随后甲也说:"那我也知道了"; 这两个数是什么?记得好像原来看过类似的一道题,具体答案忘了,只记得当时想的一些思路,但是当时没有仔细去计算最后的结果,昨天心血来潮,就想着是否可以编程计算一下,下面是关于这道题的个人想法:1)甲问乙:"你知道是哪两个 阅读全文
posted @ 2014-02-21 10:00 楠哥1991 阅读(194) 评论(0) 推荐(0) 编辑

2014年2月20日

摘要: 今天看到一道题目:#include using namespace std;class A{public:virtual void foo(int number=10){coutfoo();return 0;}问最后输出结果是多少?按照C++ Primer中关于通过积累调用被屏蔽的虚函数的讲解(C++ Primer P501)中,此处虽然a是A的指针,但是其基本对象是B类的,所以在调用foo函数时,会调用B的foo函数。那么这道题的答案是20嘛?答案是: 10原因为:虽然最终调用的是B的foo函数,但是考虑一下虚函数与默认实参的关系(C++ Primer P482),当通过基类的引用或指针调用 阅读全文
posted @ 2014-02-20 12:10 楠哥1991 阅读(296) 评论(0) 推荐(0) 编辑

2014年2月19日

摘要: 今天,同学问了一个程序上的问题,在函数A中动态分配了的内存,为什么在函数B中还会被动态分配,其值在B中进行queue声明的时候被改变了,毫无疑问,问题肯定出现在内存分配这一方面,刚开始怎么都没有想透这个问题,虽然容器在声明的时候会自动分配一定的预留内存,当时考虑到可能是两次动态分配的时候内存冲突,跟踪了半天,记录了大量的地址也没有找到冲突的地址,后来发现竟然是A中动态分配内存的地方用了临时变量取地址……虽然浪费了不少时间在这个问题上,而且看上去还是很小的一个问题,但是却学到了不少:1)临时变量申请的内存在其作用域内肯定是不变的,当出了作用域之后,如果没有重新申请临时变量,那么内存中的值依然为该 阅读全文
posted @ 2014-02-19 15:51 楠哥1991 阅读(869) 评论(0) 推荐(0) 编辑

导航