CS302 2012 Midterm Exam. James S. Plank. October 9, 2012. Answer all questions

For these programs, don't bother writing in the #include statements and using namespace std. For Question 6, you may assume that the input is always correct.

Question 5

An "ABC-10" string is a string that is ten digits long, and contains the characters A, B, and C. Write a program that prints out all ABC-10 strings that contain exactly one character C.

Question 6

Your father is a detective for the KPD, who has just spent a few thousand dollars on a program kalias that surfs the web to discover aliases for suspected criminals. Kalias runs continuously and when it discovers an alias, it prints a line of the form:

criminal XXX alias 

Criminal names can have any number of words. The aliases will be single words. For example, here are a few lines that kalias might spit out:

Francis Badmeister XXX Franky-Bad
Johnathan Constrictor III XXX Johnny-The-Strangler
Johnathan Constrictor III XXX The-KTown-Strangler
Francis Badmeister XXX Fat-Franky
Francis Badmeister XXX Frank
Johnathan Constrictor III XXX Johnny-Strong-Wrist
Johnathan Constrictor III XXX Shrink-Wrap
Francis Badmeister XXX Fat-Franky
Thor XXX Thunder-King
You'll note, sometimes it prints duplicate aliases. Your father gets irritated because this endless stream of aliases is hard for him to process. And he hates computers, of course. He wants you to write a program that does the following. It maintains all of the known aliases of each criminal. Whenever kalias emits an alias, your program should print all of the aliases for that criminal, including the new one, on one line, in lexicographic order (standard string ordering). Separate aliases by a single space. Here's an example running on the above output from kalias:
Francis Badmeister: Franky-Bad
Johnathan Constrictor III: Johnny-The-Strangler
Johnathan Constrictor III: Johnny-The-Strangler The-KTown-Strangler
Francis Badmeister: Fat-Franky Franky-Bad
Francis Badmeister: Fat-Franky Frank Franky-Bad
Johnathan Constrictor III: Johnny-Strong-Wrist Johnny-The-Strangler The-KTown-Strangler
Johnathan Constrictor III: Johnny-Strong-Wrist Johnny-The-Strangler Shrink-Wrap The-KTown-Strangler
Francis Badmeister: Fat-Franky Frank Franky-Bad
Thor: Thunder-King
I'm hoping that this is 10 minutes of programming for you. Choose the correct data structures from the STL, and make sure that you don't make excessive copies of things.