C++20 sections · 1024 units
Open in Course

Games - Algorithm

Breaking down the solution

Here's your approach:

1.1. Define a struct with two fields: home and away.

2.2. Read nn and create an array of nn team structs.

3.3. Read each team's colors into the array.

4.4. Initialize a conflict counter to 0.

5.5. Outer loop: for each team ii from 0 to n1n-1 (the host).

6.6. Inner loop: for each team jj from 0 to n1n-1 (the guest).

7.7. If iji \neq j and teams[i].home == teams[j].away, increment the counter.

8.8. Print the counter. The nested loops check every game. Structs make comparison clean: you access teams[i].home and teams[j].away without juggling separate arrays.