编程珠玑
littlestream9527
Hew out of the mountain of despair a stone of hope!
展开
-
编程珠玑第一章 习题2,习题9
// 编程珠玑第一章习题2.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include using namespace std; #define BITSPERWORD 32 #define SHIFT 5 #define MASK 0x1F #define N 10000000 int a[1 + N/BITSPERWORD]; void se原创 2013-01-18 20:20:03 · 462 阅读 · 0 评论 -
编程珠玑第二章习题3
// 编程珠玑第二章习题3.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include using namespace std; int gcd(int x, int y)// 编程之美上的高效算法 { if (x < y) swap (x, y); if (y == 0) return x; else { if ((x&1原创 2013-01-20 20:54:39 · 555 阅读 · 0 评论 -
快速计算整数的二进制表示法中1的个数(编程珠玑9章课后习题7)
http://www.cppblog.com/zenliang/articles/131761.html 题目:给定一个无符号32位整数x,求x的二进制表示法中含1的个数? 第一种算法: int OneCount(unsigned int x) { for(int count=0; x>0; count++) x&=x-1;//把最后面的1变0 r转载 2013-04-17 22:16:06 · 807 阅读 · 0 评论