Click
Here to go back to the homepage.
Exam Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int friendCorrect;
int friendWrong;
string myAns;
string friendAns;
cin >> friendCorrect;
cin >> myAns;
cin >> friendAns;
friendWrong = friendAns.length() - friendCorrect;
int myMaxCorrect = 0;
for(int i = 0; i < myAns.length(); i++){
if (myAns[i] == friendAns[i] && friendCorrect){
friendCorrect--;
myMaxCorrect++;
}
else if(myAns[i] != friendAns[i] && friendWrong){
friendWrong--;
myMaxCorrect++;
}
}
cout << myMaxCorrect;
return 0;
}