Number of character corrections in the given strings to make them equal | C ++ implementation of the approach ; Function to return the count of operations required ; To store the count of operations ; No operation required ; One operation is required when any two characters are equal ; Two operations are required when none of the characters are equal ; Return the minimum count of operations required ; Driver code
#include <iostream> NEW_LINE #include <bits/stdc++.h> NEW_LINE using namespace std ; const int minOperations ( int n , string a , string b , string c ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { char x = a [ i ] ; char y = b [ i ] ; char z = c [ i ] ; if ( x == y && y == z ) ; else if ( x == y y == z x == z ) { ans ++ ; } else { ans += 2 ; } } return ans ; } int main ( ) { string a = " place " ; string b = " abcde " ; string c = " plybe " ; int n = a . size ( ) ; cout << minOperations ( n , a , b , c ) ; return 0 ; }