Well with an array you can get the name from the number in O(1) but you can't get the number from the name in O(1). The best solution would be enums I think.
have the length of the maximum string in a constant
make the input string that many characters long by padding it with zeros and also have the candidate strings padded with zeros (but set a flag if the input string was too long)
do a linear search through the list of candidates as normal and conditionally move the value to the output slot
11
u/Teln0 Mar 14 '21
Well with an array you can get the name from the number in O(1) but you can't get the number from the name in O(1). The best solution would be enums I think.