The solution sounds complicated. 
This would set best to the var with the highest digit. 
best = right(apple,1)>right(pear,1)?apple:pear
best = right(best,1)>right(mango,1)?best:mango
Then we can split the name and number. 
name = left(best, len(best)-1)
num = int(right(best,1))
And you can lookup the prices with:
If name=“apple”
— price = tolenat("50,100,150,200", num-1, ",")
And similarly for pear and mango. 
Anyways, cheers