Here's your approach with polymorphism:
1. Define a base
Team class with virtual getHomeColor() and getAwayColor() methods.
2. Define a
StandardTeam derived class that stores and returns the colors.
3. Read n teams into an array of Team pointers.
4. Initialize count to zero.
5. For each pair (i,j) where i=j: if teams[i]->getHomeColor() equals teams[j]->getAwayColor(), increment count.
6. Output count. The polymorphic calls let you extend to new team types smoothly.