int main() { ull *N; int turn = 1, idx, tests; scanf("%d", &tests); N = malloc(tests * sizeof (ull)); for (idx=0; idx < tests; idx++) scanf("%llu", &N[idx]); for (idx=0; idx < tests; idx++) { ull cntr = N[idx]; while (cntr>1) { if (twoPow(cntr) == 0) cntr = cntr/2; else cntr = cntr - lessPow(cntr); turn++; } printf("%s\n", winner(turn)); turn = 1; } free (N); return 0; }
/// Get the number of possible values that can be switched on for the type T. /// /// \return - 0 if bitcount could not be determined /// - numeric_limits<std::size_t>::max() when overflow appeared due to /// more than 64 bits type size. static std::size_t getNumberOfPossibleValues(QualType T, const ASTContext &Context) { // `isBooleanType` must come first because `bool` is an integral type as well // and would not return 2 as result. if (T->isBooleanType()) return 2; else if (T->isIntegralType(Context)) return twoPow(Context.getTypeSize(T)); else return 1; }
void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault( const SwitchStmt *Switch, std::size_t CaseCount, const MatchFinder::MatchResult &Result) { // The matcher only works because some nodes are explicitly matched and // bound but ignored. This is necessary to build the excluding logic for // enums and 'switch' statements without a 'default' branch. assert(!Result.Nodes.getNodeAs<DeclRefExpr>("enum-condition") && "switch over enum is handled by warnings already, explicitly ignoring " "them"); // Determine the number of case labels. Because 'default' is not present // and duplicating case labels is not allowed this number represents // the number of codepaths. It can be directly compared to 'MaxPathsPossible' // to see if some cases are missing. // CaseCount == 0 is caught in DegenerateSwitch. Necessary because the // matcher used for here does not match on degenerate 'switch'. assert(CaseCount > 0 && "Switch statement without any case found. This case " "should be excluded by the matcher and is handled " "separatly."); std::size_t MaxPathsPossible = [&]() { if (const auto *GeneralCondition = Result.Nodes.getNodeAs<DeclRefExpr>("non-enum-condition")) { return getNumberOfPossibleValues(GeneralCondition->getType(), *Result.Context); } if (const auto *BitfieldDecl = Result.Nodes.getNodeAs<FieldDecl>("bitfield")) { return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context)); } return static_cast<std::size_t>(0); }(); // FIXME: Transform the 'switch' into an 'if' for CaseCount == 1. if (CaseCount < MaxPathsPossible) diag(Switch->getLocStart(), CaseCount == 1 ? "switch with only one case; use an if statement" : "potential uncovered code path; add a default label"); }