As Patrice already said, hardly anyone here will write a ready-made solution without you uploading a source code proposal.
My suggestion for the solution would be first to create a lookup table in which all necessary changes are entered. If during the creation of this table conflicts should already be noticed, one would stop with an appropriate message. In the second step you could make the changes and count them.
// edit:
The number of calls of the necessary "operation" are to be counted, thus this function is given by the task. More efficient solutions were not asked here. In particular, this function must be called several times with (freely selectable) letters that are to be replaced.
int operation(string &s, char a, char b)
{
int cnt = 0;
if (a != b) {
for (auto it = s.begin(); it != s.end(); ++it) {
if (*it == a) {
*it = b;
cnt++;
}
}
}
return cnt;
}
A lookup table can be realized with a std::map. I used the unsorted version here and defined a separate data type for it.
template<typename Key, typename Value>
using UMap = std::unordered_map<Key, Value>;
int main()
{
string str1, str2;
UMap<char, char> m; int len;
str1="bacd"; str2="abcd";
cout << "str1: " << str1.c_str() << "\n";
cout << "str2: " << str2.c_str() << "\n";
len = min(str1.length(), str2.length());
for (int i = 0; i < len; i++) {
m.emplace(str1[i], str2[i]);
}
int cnt = 0;
for (const auto& n : m) {
cnt += operation(str1, n.first, n.second); }
cout << "str1: " << str1.c_str() << " - changes: " << cnt << "\n";
return 0;
}
Note: The code is deliberately not complete here. If you add the usual includes it can be compiled. If you add the parts marked with TODO, which should be written by yourself, the task should be solved.