1998 HIGH SCHOOL PROGRAMMING CONTEST

 

Problem 1 – Quick Formatting Markup Language

Description:

Julie D. Gratist has recently acquired a TI-95 Graphing Calculator. She spent all day copying all of her text files about TCP/IP networking onto her calculator, when she was shocked and dismayed to find that the TI-95 has no text formatting functionality. Being the resourceful person she is, Julie obtained information on TI-95 ROM Programming off the Internet. Not only is Julie resourceful, but she is also competitive; she has challenged your team to write a program to implement her Quick Formatting Markup Language specifications before she can.

Quick Formatting Markup Language Definition:

All formatting codes in the Quick Formatting Markup Language begin with the character /. The bold (/b) and underline (/u) formatting codes are toggles. For instance, the first occurrence of a /b sequence will activate bold printing, and the second occurrence of a /b will deactivate bold printing. The same is true for /u sequences. For the purposes of this program bold is defined as all capital letters and underlined is defined as replacing all spaces with the underscore character (_) in addition to replacing the /u sequence itself with an underscore character (_). A tab is defined as 4 spaces.

The program should read lines of input until a blank line is entered. After the input is complete, the program should print the formatted output. (See example below.) You may assume that there are no more than 80 characters per line and no more than 10 lines of input will be entered.

Formatting Code

Functionality

/b

Toggle bold characters.

/u

Toggle underline characters.

/t

Insert a tab.

/n

Insert a new line.

//

Print a / character.

Example:

Input:

/bJohn’s Unix Quick Reference/b/n/npine/n/tRun the Pine program./n/n

kill/n/tKill a job./n/n/n//* /uDon’t kill someone else’s job./u *//

Output:

JOHN’S UNIX QUICK REFERENCE

 

pine

    Run the Pine program.

 

kill

    Kill a job.

 

 

/* _Don’t_kill_someone_else’s_job._ */

 

Additional Notes:

·      The end of one line of input does not result in a new line.

·      If a / is the last character on a line of input then it is ignored.

·      Formatting codes are case sensitive (i.e. /B is not the same as /b)

·      If a / is not followed by a valid formatting character then it is to be ignored.

·      Text can be both underlined and bold simultaneously.

·      It does not matter if underline or bold is not turned off at the end of input.

·      The Quick Formatting Markup Language does not define error messages so do not print any.