0
How to find common elements between two vectors and print the sum of the common elements?
2 Respostas
+ 8
A for each loop iterating through each element of vector A, which contains std::find to get matching elements in vector B, and then adding all matching elements to a variable sum.
+ 2
Ayshi , in addition to what Hatsy Rei has said, just look for count of elemnt in both vactor before you add elemnt to summation variable..
once you do find on other vector , it doesn't take care of repeated element.. for example, in case of vector a, 5 is present at third and sixth element where as in vector b, 5 is present at 4 position... for both entry of 5 in vector a, you should not add 5 to summation variable.