SP29 HASHIT - Hash it!
Description
Your task is to calculate the result of the hashing process in a table of 101 elements, containing keys that are strings of length at most 15 letters (ASCII codes '_A_',...,'_z_'). Implement the following operations:
- find the index of the element defined by the key (ignore, if no such element),
- insert a new key into the table (ignore insertion of the key that already exists),
- delete a key from the table (without moving the others), by marking the position in table as _empty_ (ignore non-existing keys in the table)
When performing find, insert and delete operations define the following function:
_integer Hash(string key)_,
which for a string _key_=_a_ $ _{1} $ ..._a $ _{n} $_ returns the value:
_Hash_(_key_)=_h_(_key_) mod 101, where
_h_(_key_)=19 \*(ASCII(_a_ $ _{1} $ )\*1+...+ASCII(_a $ _{n} $_ )\*_n_).
Resolve collisions using the open addressing method, i.e. try to insert the key into the table at the first free position: (_Hash_(_key_)+_j_ $ ^{2} $ +23\*_j_) mod 101, for _j_=1,...,19. After examining of at least 20 table entries, we assume that the insert operation cannot be performed.
Input Format
_t_ \[the number of test cases
Output Format
For every test case you have to create a new table, insert or delete keys, and write to the output:
the number of keys in the table \[first line\]
index:key \[sorted by indices\]