
编程之美
and1kaney
这个作者很懒,什么都没留下…
展开
-
编程之美3.9---重建二叉树&&判断结果是否能够重建
#includeusing namespace std;struct Node{Node* pLeft;Node* pRight;int nValue;};bool isValid(int * pPreOrder,int *pInOrder,int nTreeLen){if(nTreeLen==0){return true;}if(pPreOrder==NULL||pInOrder==NULL){原创 2013-07-06 14:15:10 · 790 阅读 · 1 评论 -
编程之美 2.3 寻找发帖水王扩展问题
思路和一个水王一样,每次删除四个不同的ID。 值得注意的地方:设置candidate1、candidate2、candidata3存储ID,这三个变量存储的ID不能相同。 #include using namespace std; void find(int * ID,int N) { int candidate1; int candidate2; int candid原创 2013-07-24 23:46:56 · 850 阅读 · 0 评论 -
编程之美 2.4 1的数目
问题1:写一个函数f(N),返回1到N之间出现的“1”的个数。 假设N=abcde,分别统计a、b、c、d、e位上出现的1的个数,它们之和就是总的1的个数 a位上1的个数: 若a>1,则为10000; 若a=1,则为bcde+1; a不可能为0。 b位上1的个数: 若b>1,则为(a+1)*1000; 若b=1,则为(a+1)*(cde+1); 若b=0,则为a*1000;原创 2013-07-25 11:37:52 · 594 阅读 · 0 评论