题解 | #珠玑妙算#

珠玑妙算

http://www.nowcoder.com/practice/ed21d2b1183a401797fdf06e88cc5993

class Result {
public:
vector<int> calcResult(string A, string guess) {
// write code here
multiset<char> s;
string miss;
int win = 0;
int fakeWin = 0;
vector<bool> table(A.length(), false);
for(int i = 0; i < A.length(); ++i)
{
if(A[i] == guess[i])
{
win++;
table[i] = true;
}
else
{
miss.push_back(guess[i]);
}
}</bool></char></int>

    for(char c : miss)
    {
        for(int i = 0; i < A.length(); ++i)
        {
            if(c == A[i] && !table[i])
            {
                fakeWin++;
                table[i] = true;
                break;
            }
        }
    }

    return {win, fakeWin};
}

};

全部评论

相关推荐

牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
评论
3
1
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务