C++20 sections · 1024 units
Open in Course

Domino piling - Implementation

Complete solution


plaintext
function maxDominoes(M, N)
area := M * N
return area / 2 // integer division function main()
read M, N result := maxDominoes(M, N)
print result

You pass in dimensions, get back the domino count. This makes the code readable and testable. The main function handles input and output. The formula is the same, but the function communicates purpose. The formula (m*n)/2 counts domino pairs directly. Each domino covers 2 cells, so the maximum count is total cells divided by 2. Integer division handles odd totals correctly, rounding down.