The latter doesn't sound right because it's grammatically incorrect. You wouldn't say, "I like to read book." You would say, "I like to read bookS" because you're talking about more than one.
Both "books" and "exercises" are being used as count nouns. A count noun is a noun that can be modified by a numeral and that occurs in both singular and plural forms, and that co-occurs with quantificational determiners like every, each, several, etc (Wikipedia).
"Exercises" is plural, so you like doing multiple exercises. If you only liked doing one you would say, "I like to do AN exercise."
Because this is "hacer ejercicio" (a verb) Ejercicio is not a verb by itself, unlike in English. So when you say me gusta ejercicios you're talking about exercise as a noun (a thing) not an act. I am pretty sure you'd need the article (el/los). Im not sure why it didn't ask for that too..
When a phrase like "me gusta" ends in an infinitive, the infinitive can be translated into English as either "to..." or "...-ing." "Me gusta correr" = I like to run or I like running. "Me gusta viajar" = I like to travel or I like traveling. The meaning does not change. The only difference with this sentence is that Spanish uses the expression "hacer ejercicio" for "to exercise." Translation is not an exact science. It is the art of capturing the meaning of something in one language and phrasing it properly in another.