C++20 sections · 1024 units
Open in Course

Problem - Team Uniforms

Virtual methods

You have nn teams, each with a home uniform color and away uniform color. Count how many games have a home team's uniform matching the away team's uniform (causing confusion).

This problem teaches polymorphism through a uniform-checking interface. You'll define a base class with a virtual method for getting colors, then different team types can override it.

The comparison code works with any team type through the base interface. Each team plays every other team twice: once at home, once away. When team ii hosts team jj, compare team ii's home color with team jj's away color.

Count all such matches across all game pairs.