The obstacle
Job
King Arthur and his knights are having a New Years celebration. In 2015 Lancelot was envious of Arthur, due to the fact that Arthur had a date and Lancelot did not, and they began a battle.
To avoid this from occurring once again, Arthur wishes to ensure that there are at least as numerous females as males at this year’s celebration. He offered you a list of integers of all the celebration goers.
Arthur requires you to return real if he requires to welcome more females or incorrect if he is all set.
Input/Output
[input]
integer selectionL
($ a
in PHP)
A variety (ensured non-associative in PHP) representing the genders of the participants, where -1
represents females
and 1
represents males
2 < 0)? 1: 0;.
}
[output]
Alternative 2:#include << stddef.h>>.
Alternative 3:int invite_more_women( int * arr, size_t count) {
int balance = 0;.
while (count--).
balance += * arr++;.
return balance > > 0;.
}
#include << stdbool.h>>.
, size_t count) {
#include << stddef.h>>.bool invite_more_women( const int attendee_genders
ptrdiff_t amount = 0;.
for (size_t i = 0; i < < count; i++). amount += attendee_genders
;.
return amount > > 0;.
}
#
#include << stdbool.h>>.
#include << stddef.h>>.
#include << criterion/criterion. h>>.
extern space do_test (size_t count, const int selection[i], bool anticipated);.
#define ARR_LEN( selection) (sizeof( selection)/ sizeof *( selection)).
#define sample_test( selection, anticipated) do_test( ARR_LEN( selection), selection, anticipated).
Test( tests_suite, sample_tests).
{
sample_test((( int
) {1, -1, 1} ), real);.
sample_test((( int
) {-1, -1, -1} ), incorrect);.
sample_test((( int
) {1, -1} ), incorrect);.
sample_test((( int
) {1, 1, 1} ), real);.
do_test( 0, NULL, incorrect);.
}
[]