Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to implement pairwise matches between two vectors in C++

1 Answer

0 votes
#include <iostream>  
#include <vector> 

using std::vector;
using std::cout;  
using std::endl;

int pairwise_matches(vector<int> v1, vector<int> &v2)
{
	int sum = 0;

	for (int i = 0; i < v1.size(); i++)
		if (v1[i] == v2[i])
			sum++;

	return sum;
}

int main()
{
	vector<int> v1{ 0, 1, 2, 3, 4 }, v2{ 5, 1, 2, 6, 4 };

	cout << pairwise_matches(v1, v2) << endl;

	return 0;
}

/*
run:

3

*/

 



answered Apr 25, 2018 by avibootz
...