As you finish the last group’s customs declaration, you notice that you misread one word in the instructions.
You don’t need to identify the questions to which anyone answered “yes”; you need to identify the questions to which everyone answered “yes”!
Using the same example as above:
abc
a
b
c
ab
ac
a
a
a
a
b
This list represents answers from five groups:
3
questions: a
, b
, and c
.1
question, a
. Since some people did not answer “yes” to b
or c
, they don’t count.1
question, a
.1
question, b
.In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1 =
6
.
For each group, count the number of questions to which everyone answered “yes”. What is the sum of those counts? Determine this in the following way:
group_count
that takes the “yes” answers (char*
) of one group. The answers from each person in the group are separated by spaces. The function must return the number (int
) of questions to which everyone in the group answered “yes”.plane_count
that takes the pathname (char*
) of a text file that collects the “yes” answers from every group on the plane. The function must return the sum (int
) of the number of questions to which everyone in the group answered “yes”.In this interactive session we assume the text file forms.txt
1 to be located in the current directory.
> group_count("abc")
3
> group_count("a b c")
0
> group_count("ab ac")
1
> group_count("a a a a")
1
> group_count("b")
1
> plane_count("forms.txt")
6