MAIN Home Schedule Rules Compile PROBLEMS Novice Veteran All |
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set.
Your local computer user's group publishes a quarterly newsletter, and in each issue there is a small Pascal Programming Problem to be solved by the membership. Members submit their solutions to the problem to the newsletter editor, and the member submitting the shortest solution to the problem receives a prize.
The length of a program is measured in units. The unit count is
determined by counting all occurrences of reserved words, identifiers,
constants, left parentheses, left brackets, and the following
operators: In an effort to speed the judging of the contest, your team has been asked to write a program that will determine the length of a series of Pascal programs and print the number of units in each.
Input and OutputInput to your program will be a series of Pascal programs. Each program will be terminated by a line containing tilde characters in the first two columns, followed by the name of the submitting member. Each of these programs will be syntactically correct and use the standard symbols for comments (braces) and subscripts (square brackets). For each program, you are to print a separate line containing the name of the submitting member and the unit count of the program. Use a format identical to that of the sample below.
Sample input
PROGRAM SAMPLEINPUT; VAR TEMP : RECORD FIRST, SECOND : INTEGER; END; BEGIN {Ignore this } TEMP.FIRST := 501; READLN (TEMP.SECOND); WRITELN ('THE ANSWER IS', TEMP.FIRST * TEMP.SECOND : 7); END. ~~A. N. Onymous
ExplanationThis is a list of the units in the program above: PROGRAM SAMPLEINPUT VAR TEMP RECORD FIRST SECOND INTEGER END BEGIN TEMP FIRST := 501 READLN ( TEMP SECOND WRITELN ( 'THE ANSWER IS' TEMP FIRST * TEMP SECOND 7 END
Sample output
Program by A. N. Onymous contains 28 units.
NotesHere are some additional notes on Pascal for those not familiar with the language and some simplifications for those who are overly familiar with it:
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Test Data 0
PROGRAM SAMPLEINPUT; VAR TEMP : RECORD FIRST, SECOND : INTEGER; END; BEGIN {Ignore this } TEMP.FIRST := 501; READLN (TEMP.SECOND); WRITELN ('THE ANSWER IS', TEMP.FIRST * TEMP.SECOND : 7) END. ~~A. N. Onymous
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Output for Test Data 0
Program by A. N. Onymous contains 28 units.
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Test Data 1
PROGRAM BURGERSTAND (INPUT, OUTPUT); { TAKES CUSTOMER'S ORDER AND CALCULATES AND PRINTS TOTAL COST.} CONST BURGERPRICE = 129; FRYPRICE = 79; COLAPRICE = 65; VAR BURGERORDER, FRYORDER, COLAORDER : INTEGER; TOTALBILL : INTEGER; BEGIN WRITE ('HOW MANY BURGERS? '); READLN (BURGERORDER); WRITE ('HOW MANY FRIES? '); READLN(FRYORDER); WRITE ('HOW MANY COLAS? '); READLN (COLAORDER); TOTALBILL := (BURGERORDER * BURGERPRICE) +(FRYORDER * FRYPRICE) + (COLAORDER * COLAPRICE); WRITELN; WRITELN ('TOTAL COST = $ ', TOTALBILL:1); END. ~~GREG ARIOUS
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Output for Test Data 1
Program by GREG ARIOUS contains 65 units.
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Test Data 2
PROGRAM GRADING (INPUT, OUTPUT); {CALCULATES FINAL AVERAGE USING PROF. SOLAR'S METHOD } VAR GRADE1, GRADE2, GRADE3 : INTEGER; INITIAL : CHAR; PROCEDURE ENTERDATA (VAR GRADE1, GRADE2, GRADE3 : INTEGER; VAR INITIAL : CHAR); { THIS PROCEDURE PROMPTS THE USER TO ENTER THREE GRADES AND AN INITIAL AND } { RETURNS THOSE TO THE MAIN PROGRAM. } BEGIN WRITE ('ENGER GRADE 1: '); READLN (GRADE1); WRITE ('ENTER GRADE 2: '); READLN(GRADE2); WRITE ('ENTER GRADE 3: '); READLN(GRADE3); WRITE('ENTER FIRST LETTER OF STUDETN''S LAST NAME: '); READLN(INITIAL); END; FUNCTION CALCAVERAGE (GRADE1, GRADE2, GRADE3 : INTEGER; INITIAL : CHAR) : INTEGER; BEGIN IF ODD(ORD(INITIAL) ) THEN CALCAVERAGE := ROUND((GRADE1 + GRADE2 + GRADE3)/3) ELSE CALCAVERAGE := TRUNC((GRADE1 + GRADE2 + GRADE3)/3) END; BEGIN WRITELN('SUNTANNING GRADING SYSTEM'); ENTERDATA (GRADE1, GRAD2, GRADE3, INITIAL); WRITELN; WRITE ('the student''s final average is '); WRITELN (CALCAVERAGE(GRADE1, GRADE2, GRADE3, INITIAL)) END. ~~S. S. Solar
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Output for Test Data 2
Program by S. S. Solar contains 116 units.
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Test Data 3
PROGRAM SINTABLE (OUTPUT); { PRINTS A BABLE OF SIN VALUES } CONST MAX = 1.0; INC = 0.1; VAR X : REAL; BEGIN X := 0.0; WRITELN ('X':3, 'SIN(X)':12); REPEAT WRITELN (X:5:2, SIN(X):10:5); X := X + INC UNTIL X > MAX END. ~~JOEY LUCAS
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set. Output for Test Data 3
Program by JOEY LUCAS contains 45 units.
Return to the Top of Page, 2000 Index Page, Novice Problem Set, or Veteran Problem Set.
|
This page last updated Fri Feb 11 21:55:29 2000.