Exact solutions in cosmology with a scalar field