I'm going to assume that the directions stated in this question were "51 degrees north of west" and "58 degrees south of west". Regardless of that information, however, the steps will be the same to determine the correct distance between the ships.
The first step will be to determine the location of each ship relative to port. They will each have traveled 2 hours at their listed speed and so will have traveled 26 miles and 30 miles respectively.
The location of ship A will be <-26*cos(51), 26*sin(51)> and the location of ship B will be <-30*cos(58), -30*sin(58)>. Remember that west is the negative x direction and north is the positive Y direction.
These locations are <-16.36, 20.21> for A and <-15.898,-25.441> for B, both in miles.
Use the distance formula between these two points to get their total distance sqrt[(Ax - Bx)^2 + (Ay - By)^2].
The total distance is 45.65 miles between the ships.
Don't forget the positive and negative signs when using the distance formula, because the compass bearing of each ship will greatly impact the total distance.