Justin's Words


  • Home

  • About

  • Archives
Justin's Words

一个简单的乘法算法

Posted on 2015-05-15 | In Algorithm |

现在你要计算 7562 * 423。

也就是:

1
2
3
4
5
long firstOperand = 7562;
long secondOperand = 423;
long result = 0;
for (int i = 0; i < secondOperand; i++)
result += firstOperand;

时间复杂度为 O(n)。

Read more »
Justin's Words

求最大公约数算法

Posted on 2015-05-07 | In Algorithm |

伪代码如下:

1
2
3
4
5
6
Algorithm gcd(integerOne, integerTwo)
if (integerOne % integerTwo == 0)
result = intergerTwo
else
result = gcd(integerTwo, integerOne % integerTwo)
return result

C 代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <Math.h>

int gcd(int n1, int n2)
{
int nOne = fabs(n1);
int nTwo = fabs(n2);

if (nOne == 0) return nTwo;
if (nTwo == 0) return nOne;

int result;
if (nOne % nTwo == 0)
result = nTwo;
else
result = gcd(nTwo, nOne % nTwo);

return result;
}
Justin's Words

快速排序(Quick Sort)

Posted on 2015-04-21 | In C++ |

快速排序图示(图片来自 Algorithms and Data Structures ):

QuickSort

Read more »
Justin's Words

微信公众平台信息处理(PHP)

Posted on 2015-04-03 | In PHP |

后台是 PHP 处理的,主要是获取接收到的信息类型还有组织发出的信息。

Read more »
Justin's Words

全排列(Permutation)

Posted on 2015-03-28 | In Algorithm |

全排列,比如“123”,全排列即是“123”、“132”、“213”、“231”、“312”、“321”。

Python 实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def permutation(foo):
if foo is None:
return

arr = list(foo)
def allRange(arr, start = 0, length = len(arr)):
if start is length - 1:
print('' . join(arr))
for i in range(start, length):
[arr[start], arr[i]] = [arr[i], arr[start]]
allRange(arr, start + 1)
[arr[start], arr[i]] = [arr[i], arr[start]]

allRange(arr)
Justin's Words

Scrapy 初步学习

Posted on 2015-02-28 | In Python |

这几天一直都在学 Scrapy,反正觉得它是很有用的,至少比以前独立写爬虫的时候写的代码量少多了。

安装

Scrapy 不适用于 Python 3.x 以上,所以还是得用 Python 2.x,安装如下:

1
$ pip install scrapy

记得把 Python2x/Scripts 路径加入环境变量

Read more »
Justin's Words

Pomodoro Technique

Posted on 2015-02-18 | In NoneTech |

也就是番茄工作法。

Justin's Words

匈牙利表示法(Hungarian Notation)

Posted on 2015-02-10 | In C++ |

对变量命名有很大帮助,来自 Learn Cpp.Com。

The type prefix indicates the data type of the variable.



























































Type prefixMeaningExample
bbooleanbool bHasEffect;
c (or none*)classCreature cMonster;
chchar (used as a char)char chLetterGrade;
ddouble, long doubledouble dPi;
eenumColor eColor;
ffloatfloat fPercent;
nshort, int, long
char used as an integer
int nValue;
sstructRectangle sRect;
strC++ stringstd::string strName;
szNull-terminated stringchar szName[20];
Read more »
Justin's Words

第一个 C++ 程序

Posted on 2015-02-10 | In C++ |

实际上是来自 Learn Cpp.Com 的 o(^▽^)o

io.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

double readNumber()
{
using namespace std;
double nInput;
cout << "Enter a number: ";
cin >> nInput;
return nInput;
}

void writeAnswer(double answer)
{
using namespace std;
cout << "The answer is " << answer << endl;
}
Read more »
Justin's Words

怎么设计一个程序

Posted on 2015-02-08 | In C++ |

翻译自:Learn Cpp.Com
 

一般你打算写一个程序时,想必是为了解决某种问题或者是为了模拟某种状态,不过相对新程序员来说,该怎么把这些想法转换成实实在在的代码呢?而事实上你已经从日常生活中获得很多解决问题的方法(只是不知怎么应用到程序上)。

最重要的也是最难的就是在你开始码代码之前,你应该先设计好你的程序。从很多方面来讲,编程就像建筑,相应来说,如果你还没一个建设计划就开始建筑一栋房子,除非你相当聪明,否则你的房子必然有一大堆问题:屋顶漏水或墙壁不直等。同样的,还没有个精心策划就开始写代码的话,那么在此过程中你就得花一大堆时间处理编程过程中出现的各种因为缺乏预先设计而出现的问题。

所以说,在编程中,一个精心的计划会大大减少你的时间,同时避免很多不必要的挫折。

Read more »
1…456…11
Justin Young

Justin Young

You Deserve A Better Life

107 posts
15 categories
54 tags
RSS
Github Twitter
© 2014 - 2019 Justin Young
Powered by Hexo
Theme - NexT.Mist