Answer the question
In order to leave comments, you need to log in
How to count the number of matching characters in both strings?
How to count the number of characters that are in both the first and second line?
My decision:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <clocale>
#include <string>
using namespace std;
int main()
{
setlocale(LC_CTYPE, "rus");
string a = "1234";
string b = "9321";
int p = 0;
for(int z = 0; z < 4; z++){
if(a.find(b[z]) == 0){
p += 1;
}
}
cout << p << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main()
{
std::string str1 = "just string with some numbers 124632";
std::string str2 = "1234567890 i";
std::set<std::string::value_type> setOfSymbolsInStr1(
str1.begin(),
str1.end());
std::set<std::string::value_type> setOfSymbolsInStr2(
str2.begin(),
str2.end());
std::set<std::string::value_type> intersection;
std::set_intersection(
setOfSymbolsInStr1.begin(),
setOfSymbolsInStr1.end(),
setOfSymbolsInStr2.begin(),
setOfSymbolsInStr2.end(),
std::inserter(intersection, intersection.begin()));
std::cout << intersection.size() << std::endl;
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question