This is a solve the system question. Call C the number of chickens and P the number of pigs. Each chicken and each pig has one head so the first equation is:
Each chicken has 2 legs and each pig has 4 legs so the second equation is:
To solve by substitution, first rearrange the first equation to isolate C:
Now substitute that into the second equation and solve for P:
So there are 28 pigs. Now sub that into either of the original equations. I'll use the first: