Re: Can somebody give me the whole explanation to this problem. Thanks beforehand!
Послано
Egor 24 ноя 2016 16:01
If you have two different sets A = {a1, a2, a3} and B = {b1, b2, b3, b4} then we have |A| * |B| = 3 * 4 = 12 ways to choose a pair (a[i], b[j]).
i\j b[1] b[2] b[3] b[4]
a[1] [1,1] [1,2] [1,3] [1,4]
a[2] [2,1] [2,2] [2,3] [2,4]
a[3] [3,1] [3,2] [3,3] [3,4]
Modern language solution looks like that:
map<string, int> cnt;
for (auto color : {"Blue", "Red", "Yellow"})
cin >> cnt[color];
int colors;
cin >> colors;
int ways = 1;
for (int i = 0; i < colors; i++)
{
string color;
cin >> color;
ways *= cnt[color];
}
cout << ways;
Edited by author 24.11.2016 16:04
Edited by author 24.11.2016 16:07