Implement Counting Matches
This commit is contained in:
parent
f5ce0edf4c
commit
c38e15ded6
@ -47,7 +47,7 @@ std::vector<std::string> getCodeGuessFromConsole() {
|
||||
|
||||
// TODO Make limit dynamic
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
std::cout << "Enter Digit " << i << " : " << std::endl;
|
||||
// std::cout << "Enter Digit " << i << " : " << std::endl;
|
||||
std::string input;
|
||||
std::cin >> input;
|
||||
|
||||
@ -78,6 +78,28 @@ int countPefectMatches(std::vector<std::string> &v1, std::vector<std::string> &v
|
||||
return count;
|
||||
}
|
||||
|
||||
int countMatches(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++) {
|
||||
for (int j = 0; j < shorterSize; j++) {
|
||||
if (v1[i] == v2[j]) {
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -92,6 +114,7 @@ void Aufg5Main() {
|
||||
printAllStringsInVector(SecretCode);
|
||||
|
||||
std::vector<std::string> guess = getCodeGuessFromConsole();
|
||||
std::cout << "correct were: " << countPefectMatches(guess, SecretCode) << std::endl;
|
||||
std::cout << "correct were: " << countMatches(guess, SecretCode) << std::endl;
|
||||
std::cout << "perfect were: " << countPefectMatches(guess, SecretCode) << std::endl;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user