Problem D
Select Group
Playing the popularity game is all about getting yourself into the right groups. If you are on the football team and the honor roll, this might impress some people. If you are in the AV club, chess club, and academic probation, perhaps not so much. For this problem, develop a program that computes the set of people inside or outside various groups.
Input
Input begins with the description of a collection of up to
100 groups. Each group starts with a line of the form “group
-
Where is the name of a group, selects the set of individuals in group . -
union
Where and are selection expressions, selects the set of individuals in (selected by) either or -
intersection
Where and are selection expressions, selects the set of individuals in both and -
difference
Where and are selection expressions, selects the set of individuals in but not in
Each selection expression contains up to 100 group names and set operations.
The sequence of select statements ends at the end of file. No group will have the name group, union, intersection or difference. Different people will have different names; different groups will have different names.
Output
For each selection expression, print out a single line giving the set of individuals selected. Names on each output line should be space separated and printed in lexicographic order.
Sample Input 1 | Sample Output 1 |
---|---|
group geeks 3 Trevor Chet Kari group jocks 3 Chet Mary Bert group popular 4 Kari Selma Aaron Mary group Trevor 1 Trevor union geeks jocks intersection geeks union jocks popular union geeks union difference jocks popular Trevor |
Bert Chet Kari Mary Trevor Chet Kari Bert Chet Kari Trevor |