Implement Counting perfect Matches

This commit is contained in:
Matti 2024-11-13 21:29:55 +01:00
parent 1d32b4798d
commit f5ce0edf4c

View File

@ -59,6 +59,25 @@ std::vector<std::string> getCodeGuessFromConsole() {
return guess; return guess;
} }
int countPefectMatches(std::vector<std::string> &v1, std::vector<std::string> &v2) {
int shorterSize;
if (v1.size() < v2.size()) {
shorterSize = v1.size();
} else {
shorterSize = v2.size();
}
int count = 0;
for (int i = 0; i < shorterSize; i++) {
if (v1[i] == v2[i]) {
count++;
}
}
return count;
}
@ -73,5 +92,6 @@ void Aufg5Main() {
printAllStringsInVector(SecretCode); printAllStringsInVector(SecretCode);
std::vector<std::string> guess = getCodeGuessFromConsole(); std::vector<std::string> guess = getCodeGuessFromConsole();
std::cout << "correct were: " << countPefectMatches(guess, SecretCode) << std::endl;
} }