How many $5 bills did hermione have in her purse?

Let x=the number of $1 bills she has, and let y=the number of $5 she has. From the information given, we can say:
x+5y=40
x+y=12
When you subtract the first equation from the second equation, you get:
x+5y-x-y=40-12
4y=28
y=7
Therefore, Hermione has 7 $5 bills in her purse.