f(str) return v[s.first-char] + v[s.last-char] + s.length
and a set of words, assign values to v
to avoid collisions,
subject to
0 ≤ v[i] ≤ 15
v
as a 26-digit hexadecimal number.
v = 0 while v < 0xfffffffffffffffffffffffffff if no-colisions(v, words) break v++
v
.
v
to a n-digit number, where n distinct
letters start or end the words.
v
fails, where's the problem?
solve(words, encoding) if words is empty // success else pick a word in words while encode word compare for collisions if not found solve(words - word, encoding) // failure
words
?
f[word.first] + f[word.last]
set 1 | set 2 | set 3 | |
---|---|---|---|
Unsorted | 13.2 | 3.6 | 30.3 |
Sorted | 0.2 | 0.0 | 0.0 |
set 1 | set 2 | ||
---|---|---|---|
Unsorted | 0.6 | 2.1 | 9.7 |
Sorted | 0.7 | 3.9 | 9.7 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
1 | ||||||||||
2 | ||||||||||
3 | ||||||||||
4 | ||||||||||
5 | ||||||||||
6 |
a 0 b 0 c 0 d 0 e 0 f 0 g 0 h 0
is not the required output format.
int StrLenMatrix::getIndex(char start, char end) { // get index for start/end char location if ( (start == 'a' && end == 'a') || ( end == 'a' && start == 'a')) return 0; if ( (start == 'a' && end == 'b') || ( end == 'a' && start == 'b')) return 1; if ( (start == 'a' && end == 'c') || ( end == 'a' && start == 'c')) return 2; if ( (start == 'a' && end == 'd') || ( end == 'a' && start == 'd')) return 3; if ( (start == 'a' && end == 'e') || ( end == 'a' && start == 'e')) return 4; if ( (start == 'a' && end == 'f') || ( end == 'a' && start == 'f')) return 5; if ( (start == 'a' && end == 'g') || ( end == 'a' && start == 'g')) return 6; if ( (start == 'a' && end == 'h') || ( end == 'a' && start == 'h')) return 7; if ( (start == 'a' && end == 'i') || ( end == 'a' && start == 'i')) return 8; // And so on.
stop and think.
class Hash { string word; Hash() {} Hash(const string& s, int hv) {} int last_value() char last_char = word.at(word.size() - 1)
if cap = 0 strArray = new string[1] cap++ else if cap == size string * newArray = new string[2*cap] if 0 = newArray cerr << "! Not sufficient capacity" exit(1)
new
throws bad_alloc
.new(nothrow)
returns 0.
void find_characters() for (i = 0; i < largest; i++) if (i==0) for (j = 0; j < countarray[i]; j++) string str = lengtharray[i][j] carray[indx1][indx2[indx1]++] = str[0] indx1++ else for (j = 0; j < countarray[i]; j++) string str1 = lengtharray[i][j] carray[indx1][indx2[indx1]++] = str1[str1.size()-1] indx1++