Cs50 Pset3,领带功能

问题描述 投票:0回答:1

// Return true if the election is tied between all candidates, false otherwise
bool is_tie(int min)
{
    // TODO
    for (int i = 0; i < candidate_count; i++)
    {
        int v = candidates[i].votes;
        while (candidates[i].eliminated == false)
        {
            if (candidates[i].votes == min && candidates[i++].votes == min)
            {
                return true;
            }
            if (v < candidates[i++].votes)
            {
                return false;
            }
            if (candidates[i].votes > min )
            {
                return false;
            }
        }
    }
    return false;
}

This is what I need to get around


:( 当选举没有平局时 is_tie 返回 false

is_tie 没有返回 false

:( 当只有部分候选者平局时 is_tie 返回 false

is_tie 没有返回 false






Any hint towards what to do would be much appreciated, Have a good day ! 
!!!!!!!!!!!DO NOT GIVE ME THE AWNSER!!!!!!!!!
cs50
1个回答
0
投票

要求是“如果选举在all候选人之间平局,则返回 true”[强调]。如果只有两个候选人并列,则此函数返回 true (

if (candidates[i].votes == min && candidates[i++].votes == min)
)。

请注意:当

if
等于最大值时,使用
i++
进行
i
测试可能会出现超出范围的错误。更不用说:函数并不关心
candidates[i++]
是否被消除!

© www.soinside.com 2019 - 2024. All rights reserved.