求两个日期间相隔的天数

这两天在网上看到了一道求两个日期间相隔天数的题目,想到了一个实现的方法:

import time
time1 = raw_input("Please input time1:")
time2 = raw_input("Please input time2:")
timeStamp1 = int(time.mktime(time.strptime(time1,"%Y-%m-%d")))
timeStamp2 = int(time.mktime(time.strptime(time2,"%Y-%m-%d")))
diff = abs(timeStamp1 - timeStamp2)
print diff/24/60/60

Compare Version Numbers

Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.

You may assume that the version strings are non-empty and contain only digits and the . character.
The . character does not represent a decimal point and is used to separate number sequences. Continue reading

Word Frequency

Write a bash script to calculate the frequency of each word in a text file words.txt.

For simplicity sake, you may assume:

  • words.txt contains only lowercase characters and space ' ' characters.

  • Each word must consist of lowercase characters only.

  • Words are separated by one or more whitespace characters.

Continue reading