Answer
a. Remember the formula that relates heat transfer to specific heat capacity, mass, and temperature change: $Q = cm \Delta T$.
Heat gained by the water = Heat lost by the nails. The water warms up while the nails cool down. We consider only the size of the temperature change in the following equation.
$$(cm \Delta T)_{water}=(cm \Delta T)_{nails}$$
$$\frac{1 cal}{g \cdot ^{\circ}C}(100 g)(T - 20^{\circ}C) = \frac{0.11 cal}{g \cdot ^{\circ}C}(100 g)(40^{\circ}C - T) $$
$$9.091(T - 20^{\circ}C) = 40^{\circ}C - T$$
$$10.091 T= 221.8^{\circ}C$$
Solve for $T = 22^{\circ}C$.
b. It's true that the masses are the same, but the specific heat capacity of iron is very much lower than that of water. In dropping 18 degrees, 100 g of iron releases an amount of heat that only raises the temperature of 100 g of water by 2 degrees. Water has a relatively high thermal inertia compared to iron.