In this project you need to use Binary Search Tree. Input Data is a text file containing a keyword in a line, prefixed by an operator
+
for insertion
-
for deletion
For example:
In this project you need to implement some basic graph operations.
Suppose program name is graph and distance.txt is a text file.
After the "distance.txt" has been read in the memory and the data structure built, the program will enter interactive mode by prompting >
to let user enter commands.
The program should print >
for prompting after the execution of each command.
Input Data: a text file containing two locations and distance between two locations in a line.
For example:
Taipei Ilan 4
In this project, you need to write a tool named “tcount” that will count the occurrences of terms in a given file. You will use hashing data structure to implement the tool.
The test data contains a dictionary file and a text file. For each term in the dictionary, count the occurrence number in the text file.
For example suppose the dictionary file contains:
apple pie
所求
= sum([x for x in range(1, 1000) if x % 3 is 0 or x % 5 is 0])
= 3 的倍數和 + 5 的倍數和 - 15 的倍數和
= (3+6+...+999) + (5+10+...+995) - (15+30+...+990)
= ((3 + 999) * 333 / 2) + ((5 + 995) * 199 / 2) - ((15 + 990) * 66 / 2)
= 233168
def fib():
f0 = 1
f1 = 2
yield f0
yield f1
f = f0 + f1
while f <= 4000000:
from math import sqrt
def is_prime(N, primes):
for p in primes:
if p*p > N:
break
if N % p is 0:
return False
def is_plaindrome(N):
temp = N
rev = 0
while N is not 0:
digit = N % 10
rev = rev * 10 + digit
N = N // 10
return temp == rev
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return max(a, b) // gcd(a, b) * min(a, b)
ans = 1
a = 100*101*201 // 6
b = ((1 + 100) * 100 // 2) ** 2
print(b - a)
def is_prime(N, primes):
for p in primes:
if p * p > N:
return True
if N % p is 0:
return False
return True
primes = [2, 3, 5, 7]