Multiplying Two Matrices
Kestrel Couriers moves every parcel in two legs. The first table has one row per hub and one column per depot: it says how many vans run that hub-to-depot route each night. The second table has one row per depot and one column per city: it says how many parcels a van arriving at that depot carries onward to each city. Planning wants the end-to-end picture — for each hub and each city, how many parcels leave that hub and reach that city, counting every depot they could pass through. That is the ordinary matrix product of the two tables, with the hub-to-depot table on the left.
Task: Print the hub-to-city table.
Input
Four lines, each holding two whole numbers separated by a space. The first two lines are the hub-to-depot table, one row each. The next two lines are the depot-to-city table, one row each.
Output
Two lines, each holding two whole numbers separated by a single space: the hub-to-city table, one row per hub.
Example:
Input:
1 2
3 4
5 6
7 8
Output:
19 22
43 50
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in