27 Jun 2011
Free C and C++ books
Copy from: http://www.lighthouse3d.com/2011/06/free-c-and-c-books/
Some freely available books, some out of print, some still available in online stores, others in plain HTML.
Thinking in C++ 2nd Edition (2 Volumes) by Bruce Eckel - This is probably the most famous one. There is also a printed version on sale.
An Introduction to GCC, by Richard M. Stallman - A GNU C and C++ manual for those who want ot get started with the GNU compilers, gcc and g++.
Nectarine City Handbook of C Programming Style by Joseph Miklojcik – A book on writing clear code.
The C Book by Mike Banahanm Declan Brady and Mark Doran – The online version of “The C Book”, published by Addison Wesley in 1991 (no longer in print)
Introduction to C Programming by Rob Miles – A online introductory C book.
C Elements of Style by Steve Oualline – Building good programming style
C++ Annotations by Frank B. Broken – Moving from C to C++
12 Jun 2011
.NETstring^到char*的转换
.NETstring^到char*的转换 .net中都是string^类型,如果要使用旧版c++的char*,可以如下转换
// convert from string to char*
char *str2chars(String ^s)
{
char *pHead, *pInd;
pHead = pInd = new char[s->Length+1];
for (int i=0;i<s->Length;++i)
*pInd++ = s[i];
*pInd = '\0';
return pHead;
}
10 Jun 2011
Euler Project8 欧拉工程第八题
Find the greatest product of five consecutive digits in the 1000-digit number.
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450
计算上面100位数中,连续5个数字的最大乘积.
只有100位数字,暴力循环即可.每次取5个数,如果包含0,乘积是0,直接跳过;如果这5个数中max-min大于4,则这5个数不连续.
代码:
%% greatest product of five consecutive digits
% Elapsed time is 0.042594 seconds.
% ans =
% 40824
function result = euler8()
tic;
s = '7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450';
result = 0;
for i=5:length(s)
temp = s(i-4:i);
if ismember(0,temp) || max(temp)-min(temp)>4 % 0 or not consecutive digits
continue;
end
result = max([result,prod(str2num(temp(:)))]);
end
toc;
end
9 Jun 2011
hhc.exe制作chm
反编译chm后,如果修改了内容,需要编译成chm,按照如下方法即可: 制作chm帮助文件,很多软件制作CHM都是调用hhc.exe,比如国产软件QuickCHM,就是调用了hhc.exe
微软的HTML Help Workshop也是调用了hhc.exe,比如我们安装完HTML Help Workshop之后,
在它的安装目录就会看到,有hhc.exe和hha.dll这两个文件。
hhc.exe可以用命令行操作,非常简单,只需要一个参数
hhc.exe C:\makechm\aa.hhp
hhp这个文件是工程文件,hhc是目录文件,hhk是index目文件。
hhp文件可自己新建,按照如下格式写好路径:
[OPTIONS]
Compiled file=C:\Documents and Settings\Administrator\桌面\test.chm
Contents file=test.hhc
Index file=test.hhk
Title=test
[FILES]
mark.htm
C:\fkchm\compile_date.htm
C:\fkchm\scanner_camera_add.htm
C:\fkchm\scanner_camera_deletepix.htm
用命令行反编译CHM文档
现在很多电子书都是CHM格式的,它们是HTML打包生成的。网上有很多的生成CHM和反编译CHM的工具,有很多还是收费的。而最近我发现了一个命令,是Windows自带的一个反编译Chm的命令。
命令行格式输入:
hh -decompile X:\A Y:\B.chm
其中 X:\A是反编译后储存文件的路径, Y:\B.chm是CHM文件的路径。
回车即可在X:\A中找到反编译的文件,连hhc和hhk都有!hhc是CHM的目录结构文件,hhk是CHM的元数据文件。。
Euler Project7 欧拉工程7
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10001st prime number?
寻找第10001个素数.
%% find 10001's prime number
% ======use primes==========
% Elapsed time is 0.008245 seconds.
% ans =
% 104743
function result = euler7()
tic;
x = primes(200000);
result = x(10001);
toc;
end
用循环的办法:
% ======use loop===========
% Elapsed time is 5.486655 seconds.
% ans =
% 104743
function result = euler7()
n = 0;
result = 1;
while n<10001
result = result+1;
if isprime(result)
n = n+1;
end
end
end
Euler Project6 欧拉工程6
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
计算前100个自然数"和的平方"与"平方的和"的差值.
%% Find the difference between the sum of the squares of 1:100 and the square of the sum.
% Elapsed time is 0.000032 seconds.
% ans =
% 25164150
function result = euler6()
tic;
x = 1:100;
result = sum(x).^2-sum(x.^2);
toc;
end
7 Jun 2011
python tips - 转分数为小数
UPDATE: 新函数cmpfrac()可以用来求循环节长度.
将分数转换为循环小数,默认处理1/d的情况,输出50位.稍加修改,可以变成处理互质的a/b的程序.
代码如下:
5 Jun 2011
python模仿matlab的tic/toc计时
python模仿matlab的tic/toc计时
python有自己的timeit模块,但是用惯了matlab的tic/toc,模仿了一个,需要用到globals()函数.实现方法如下:
4 Jun 2011
每次打开Office2007都要重新配置解决办法
每次打开word2007都要重新配置解决办法如下:
1,最简单: win+R(或者开始-运行),输入:
reg add HKCU\Software\Microsoft\Office\12.0\Word\Options /v NoReReg /t REG_DWORD /d 1
然后回车即可.2.打开电脑C盘路径,C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller里面的SETUP改成SETUPa就可以了.
经验证,1只可解决word问题,如果excel也一样的问题,即使修改注册表那行把word改成excel还是不行;
2可以直接解决所有问题.推荐第二个办法.
2 Jun 2011
xp删除"拒绝访问"的文件夹
删除"拒绝访问"的文件夹 方法如下:
在XP中的“文件夹选项”的“查看”选项卡下去掉“使用简单文件共享(推荐)”复选框。
"拒绝访问"文件夹的“属性”->“安全”->“高级”-〉“所有者”-〉“目前该项目的所有者”
如果类似是"S-1-5-21-1528117516-2020809315-3846545974-1000"的代码,“将所有者改为”当前管理员账户,勾选“替换子容器及对象的所有者”,“确定”。
打开“高级安全设置”的“权限”选项卡下,勾选“从父项继承....,..明确定义的项目”复选框和“用在此显示的可以应用到子对象的项目...............”复选框,“确定”。
完成后就可以直接删除"拒绝访问"的文件夹了,包括Vista的。
Subscribe to:
Posts
(
Atom
)