当前位置: 首页>>代码示例>>C++>>正文


C++ code::getSecret方法代码示例

本文整理汇总了C++中code::getSecret方法的典型用法代码示例。如果您正苦于以下问题:C++ code::getSecret方法的具体用法?C++ code::getSecret怎么用?C++ code::getSecret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code的用法示例。


在下文中一共展示了code::getSecret方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkIncorrect

//  input:
//      code guess - a code object containing the user's guess
//  output:
//      int incorrect - the number of digits in the guess that exist in the secret, but are not correctly placed
//
//  Check how many digits are part of the secret code, but were guessed at wrong positions. If an index is set to 6
//  we know that the index has been covered and will skip it. If an element in the same spot in secretDigits is set to 6,
//  this also means that the value has been covered.
//  ASSUMPTION: This is called AFTER checkIncorrect so that it will only check indices that haven't been confirmed
int code::checkIncorrect(code guess) {
    vector<int> userGuess = guess.getGuess();
    vector<int> secretCode = guess.getSecret();
    vector<int> secretDigits = getDigits();

    int incorrect = 0;
    for (int i=0; i < userGuess.size(); i++) {
        //Index has already been confirmed, move on
        if (userGuess[i] == 6) {
            continue;
        }
        //Digit IS part of solution, HAS NOT been verified by checkCorrect, but in wrong place
        if (find(secretDigits.begin(), secretDigits.end(), userGuess[i]) != secretDigits.end() && userGuess[i] != secretDigits[i] && secretDigits[i] != 6) {
            incorrect += 1;
            userGuess[i] = 6;
            secretDigits[distance( secretDigits.begin(), find(secretDigits.begin(), secretDigits.end(), userGuess[i]))] = 6;
        }
    }

    setDigits(secretDigits);
    return incorrect;
}
开发者ID:eric-cc-su,项目名称:CodeBits,代码行数:31,代码来源:code.cpp


注:本文中的code::getSecret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。