本文整理汇总了C++中Code::getLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Code::getLength方法的具体用法?C++ Code::getLength怎么用?C++ Code::getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Code
的用法示例。
在下文中一共展示了Code::getLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkIncorrect
// Compares guess to secret code and returns the number of correct digits
// in the incorrect locations.
int Code::checkIncorrect(Code& guess) {
const int secretCodeLength = getLength();
int count = 0; // correct digits in the incorrect location
vector<bool> secretUsed = getUsed();
vector<bool> guessUsed = guess.getUsed();
/// check vector lengths
if (guess.getLength() != secretCodeLength) {
throw InvalidVectSize("Code::checkCorrect - vectors are not the same length!");
}
// compare all unused guess values to current unused secret code value
for (int i = 0; i < secretCodeLength; i++) {
for (int j = 0; j < guess.getLength(); j++) {
if ((!secretUsed[i] && !guessUsed[j]) &&
(getCode()[i] == guess.getCode()[j] )) {
// we have a match, mark these indices as used and
// increase the count before continuing the compare
secretUsed[i] = true;
guessUsed[j] = true;
count++;
break;
}
}
}
return count;
}
示例2: checkCorrect
// Compares guess to secret code and returns the number of correct digits
// in the correct locations.
int Code::checkCorrect(Code& guess) {
const int secretCodeLength = getLength();
int count = 0;
vector<bool> correct(secretCodeLength, false);
/// check vector lengths
if (guess.getLength() != secretCodeLength) {
throw InvalidVectSize("Code::checkCorrect - vectors are not the same length!");
}
for (int i = 0; i < guess.getLength(); i++) {
if (getCode()[i] == guess.getCode()[i]) {
// mark both the secret and guess code index values if used
correct[i] = true;
count++;
}
}
setUsed(correct);
guess.setUsed(correct);
return count;
}