You learned that virtual methods let derived classes provide their own implementations while callers use the base interface. This decouples the algorithm (counting matches) from the data representation (how teams store colors).
Polymorphism through pointers or references enables runtime dispatch.
The all-pairs comparison pattern appears often. You iterate from 0 to n-1, then from 0 to n-1, skipping .