Problem B
Class Picture
It’s time to take a class picture. As you know, this means all of the students have to line up in a row and smile for the camera. Of course, like any class, there are pairs of people who don’t like each other. These people refuse to stand beside each other for the picture. If possible, you must figure out an order in which to arrange the class so that nobody is standing beside a classmate they don’t like.
Input
Input contains descriptions for up to
Each name is a sequence of upper- and lowercase letters
(a-z) at most
Output
For each class, your program should print out a line giving a sequence of names that could serve as an order people could stand for the class picture. If no order exists, you should simply print out “You all need therapy.” If there is more than one solution, your program should print out the lexicographically earliest solution (i.e., the solution with the alphabetically earliest possible name first, then the alphabetically earliest possible name second and so on). Sort using ASCII ordering, so that uppercase letters are sorted before lowercase letters.
Sample Input 1 | Sample Output 1 |
---|---|
5 Ron George Bill Fred Jenny 3 Fred Jenny Bill Ron George Jenny 2 Alice Bob 1 Alice Bob |
Bill Fred George Ron Jenny You all need therapy. |