Let's write it down in mathematical terms:
x-y=5
so
x=5-y
this means:difference between two numbers is 5
2y=x+18
this means: twice the smaller number is 18 more than the larger number
and we can substitute the x for what we said before:
2y=(5-y)+18
we add 1 y from each side:
3y=5+18
3y=23
so the smaller number is 23 and the bigger number is 23+5=28.