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