Problem #1

No Comments, Please

 

Input File: CommentIn.txt

Output File: CommentOut.txt

Program File: Comment

 

Compilers, unlike experienced programmers, hate comments. They consider them useless junk mail and simply discard them. Your programming team is writing a compiler for a new programming language. You have been given the task of removing all comments from the source code as a first step in the translation process.

 

In the new language, there are two types of comments: single-line and multi-line comments. Both types of comments begin with two keystrokes:

 // for single-line comments

/* for multi-line comments.

 A new line character terminates the single-line comment while the double keystroke: */ terminates a multi-line comment. The two characters of the multi-line terminator must be on the same line. You are to discard the “junk mail” comments but otherwise leave the program exactly as originally written.

 

Inputs

The text of the program containing single and multi-line comments.

 

Outputs

The text of the program exactly as written, with all comment removed.

 

Sample input

/*  / Programmer: Joe Smith

/ Program: Project 1, Version 1.1/2**

/ Date: 6/7/01 */

class P1// main class

begin:

   integer a, b, c;

   input a , b;

   c = (a+b)/c/d;          // compute the result

/*******    produce the outputs    ********/   output a;

   output c;

// terminate the program

end;

 

Sample output

class P1                       

begin:

   integer a, b, c;

   input a , b;

   c = (a+b)/c/d;         

   output a;

   output c;

end;

 

 

 

 

Problem #2

Portfolio of futures contracts

 

Input File: Portfolioin.txt

Output File: Portfolioout.txt

Program File: Portfolio

 

 

Your cousin Enron trades in stock futures contracts and is very interested in the value of his financial portfolio at any given time.  A “futures contract” is the right to purchase a specific stock at a specific price per share (the futures price) sometime in the future. Enron wants to be able to calculate his position (hypothetical profit or loss) on each of his equity futures contracts.

 

His position will be a loss if the current price per share of the stock is below the contracted futures price, or a gain if the current price per share of the stock is above the contracted futures price. For each of his futures contracts in his portfolio, he would like to know his gain or loss and, in addition, the total gain or loss of all the contracts in his portfolio.

 

Inputs

For each stock: the stock ticker symbol, number of shares, current stock price per share and futures price per share. A stock ticker symbol of –999 will indicate the end of the inputs.

 

Outputs

There will be one output line per stock displaying its ticker symbol and current position (gain/loss) amount. Finally, there will be one line showing the total value of all of Enron’s futures contracts.

 

 

Sample input

DIS

5

23.15

26.00

MSFT

1000

61.20

60.00

GM

1000

64.30

64.30

-999

Sample output
Your position in DIS is at a loss of $14.25
Your position in MSFT is at a gain of $1200.00
Your position in GM is even at $0.00
Your total position is $1185.75

 

 

 

Problem #3

Mom and Pop’s Inventory

 

Input File: InventoryIn.txt

Output File: InventoryOut.txt

Program File: Inventory

 

The local Mom and Pop hardware store is having trouble keeping track of the value of their inventory. Inventory records are stored in a disk file with one entry for each type of item in the store. An inventory record contains the name of the item, the price, the manufacturer and the quantity remaining in stock. Your task is to print out all the inventory records (with the manufacturer shown first) followed by the total value of the inventory and  the total number of items in the store inventory.

 

 

Inputs

One record per item in the inventory giving the name of the item, the price, the manufacturer and the quantity in stock

 

Outputs

All the inventory records, with the manufacture shown first, followed by the name of the item, its price and quantity in stock. Finally, output the total dollar value of the inventory and the total number of items in the inventory.

 

Sample input

Hammer 11.99 Stanley 22

Paint 18.59 Walltec 54

Saw 8.56 Cutrite 3

Bulbs 5.99 GE 18

 

Sample output

Stanley Hammer 11.99 22

Walltec Paint 18.59 54

Cutrite Saw 8.56  3

GE Bulbs 5.99 18

1401.14           97

 

 

Problem #4

Roman Numerals

 

Input File: Romanin.txt

Output File: Romanout.txt

Program File: Roman

 

Your very ancient Uncle Caesar Augustus has just moved to New York from Italy.  He has mastered the English language but is having lots of difficulty with our number system since he only knows Roman numerals.  Write a program to help your dear old Uncle convert the integer values ranging from 1 to 2000 into Roman numerals.

 

Rules for Roman Numerals:

The integers 1, 5, 10, 50, 100, 500 and 1000 are represented by Roman characters whose integer values are: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000.

 

In addition to the Roman characters there are Roman pairs, which are two Roman characters with the first character always smaller than the second. For example: IX or IV. The integer value of the pairs is the result of subtracting the integer value of the first character from that of the second character: IV has a value of 4 = (5 –1). There are two special rules for forming these pairs:       1) Only I, X, and C can be the first character in the pair; V, L and D cannot.

2) The integer value of the first character must be no less than a tenth of the value of the integer value of the second character. For example: an X (10) can be placed to the left of a C (100) or an L (50) but not to the left of an M (1000) or a D (500).

 

Integer numbers are represented as Roman numerals using Roman number sequences. Roman number sequences are sequences of one or more Roman characters or pairs such that the sum of the integer values of the characters and pairs equals the integer number to be represented.

The characters and pairs that make up the Roman number is always arranged so that their integer values are in ascending order from left to right. For example 1109 is MCIX not CIXM nor IXMC nor IXCM.  When possible, pairs are always used in place of characters (4 is IV not IIII).

 

Inputs

Integer values between 1 and 2000 inclusive.

Outputs

The Roman Numeral representation of the input integers.

Sample input

10

19

1500

490

95

999

277

1829

49

Sample output

X

XIX

MD

CDXC

XCV

CMXCIX

CCLXXVII

MDCCCXXIX

XLIX

 

 

Problem #5

Jumble Characters

 

Input File: Jumblein.txt

Output File: Jumbleout.txt

Program File: Jumble

 

 

Your Uncle Thaddeus loves to do the word jumble puzzles in the newspaper. To help him, create a program that can show every permutation possible for a given string of characters.

 

Inputs

The number of characters in the character string (to be permutated) followed by the character string.

 

Outputs

A numbered list, in alphabetical order, of all possible permutations of the characters in the string.

 

 

Sample input

3

bac

 

Sample output

1) abc

2) acb

3) bac

4) bca

5) cab

6) cba

 

 

 

Problem #6

Marty the Wonder Mouse

 

Input File: MazeIn.txt

Output File: MazeOut.txt

Program File: Maze

 

Your pet mouse Marty can find his way out of a maze, unassisted, much to the delight of his fans. The maze is divided into a two dimensional grid of six rows and six columns of black and white tiles. Tiles are identified by their row number followed by their column number. Row and columns are numbered sequentially from 0 to 5 with box 0,0 in the upper left corner.  Black tiles cannot be stepped on so Marty must proceed along the white tiles of the maze to reach the exit.

 

Marty always enters the maze from below, stepping onto tile 5,1 which is always a white tile. From there he can advance to any adjacent white tile, but cannot travel diagonally from tile to tile. If possible, Marty will always continue straight ahead. Being left handed his second choice is always to turn left, then right and finally (if he has reached a dead end) his last and only remaining choice is to retreat. You act as Marty’s announcer calling out Marty’s locations to his adoring fans as he moves from box to box, including when he retreats.

Inputs

A line containing the row and column number of the exit followed by six more lines that describe rows 0 through 5 of the maze. In the row description lines, a black tile is represented as a 1 and a white tile is represented as a 0.

Outputs

The row and column numbers of the tiles Marty steps on as he finds his way through the maze, including all the boxes backtracked onto because Marty chose a path that ended in a dead end.

Sample input

0  3

1  1  1  0  1  1

1  1  1  0  1  1

1  0  0  0  0  1

1  1  0  1  1  1

1  0  0  0  0  1

1  0  1  1  1  1

Sample output

5 1

4 1

4 2

4 3

4 4

4 3

4 2

3 2

2 2

2 1

2 2

2 3

2 4

2 3

1 3

0 3