C++20 sections · 1024 units
Open in Course

Team Uniforms - Algorithm

Implementation approach

Here's your approach with polymorphism:

1.1. Define a base

Team class with virtual getHomeColor() and getAwayColor() methods.

2.2. Define a

StandardTeam derived class that stores and returns the colors.

3.3. Read nn teams into an array of Team pointers.

4.4. Initialize count to zero.

5.5. For each pair (i,j)(i, j) where iji \neq j: if teams[i]->getHomeColor() equals teams[j]->getAwayColor(), increment count.

6.6. Output count. The polymorphic calls let you extend to new team types smoothly.