1996 High School Programming Contest

Document Sample
1996 High School Programming Contest Powered By Docstoc
					UM-F Student Chapter of the                                           2006 High School Programming Contest
Association for Computing Machinery            Computer Science, Engineering Science, and Physics Department




                                        FIFTEENTH
                                           Annual
                     High School Programming Contest
                                            at the

                                 University of Michigan-Flint
                                     Friday May 5, 2006



                                          Hosted by

     The UM-F Student Chapter of Association for Computing Machinery

                                             and

     The Computer Science, Engineering Science, and Physics Department
UM-F Student Chapter of the                                                     2006 High School Programming Contest
Association for Computing Machinery                      Computer Science, Engineering Science, and Physics Department



                                The University of Michigan-Flint
                                15th Annual High School Programming Contest

                                      sponsored under the joint auspices of

                  The Computer Science, Engineering Science, and Physics Department

                                                      and

                The UM-F Student Chapter of the Association for Computing Machinery

                                              Friday May 5, 2006



         Welcome to the 2006 High School Programming Contest

Schedule of Events
 8:00 - 8:30 A.M.             Registration & Photo-Ops            109 MSB

 8:30 – 8:45 A.M.             Welcome                        109 MSB
                              ** Dr. R. Shantaram
                                      Contest Director and Faculty Advisor, ACM-Chapter
                              ** Ryan Dowling
                                      Chair, UM-F Student Chapter of the ACM
                              ** Mark Mercado
                                      Vice-Chair, UM-F Student Chapter of the ACM
                              ** Jon Peer
                                      Treasurer, UM-F Student Chapter of the ACM
                              ** Josh Sharich
                                      Secretary, UM-F Student Chapter of the ACM

 8:45 - 9:00 A.M.             Information Session                 Room 106/104 MSB

 9:00 - 1:00 P.M.             Contest                             Room 106/104 MSB

 1:00 – 2:30 P.M.             Lunch & Awards Ceremony             Room 109 MSB
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department



                                      Contest Administration
                                               R. Shantaram
                                       CSESP Faculty and Contest Director


Jeff Barrett, ACM Member                                    Jim Norcross, Systems Administrator
Matt Beier, ACM Member                                      Chris Pearson, CSESP Faculty
Joey Cheng, ACM Officer                                     Jon Peer, ACM Officer
Loretta Dauve, CSESP Chair                                  Nick Perry, CSESP Major
Ryan Dowling, ACM Chair                                     Robert Powers, ACM Member
Kelly , Edwards, ACM Member                                 Adam Robinson, ACM Member
Mike Farmer, CSESP Faculty                                  Mehrdad Simkani, Math Faculty & Judge
Quentin Galerneau, CSESP Faculty & Judge                    Mary Spear, ACM Member
Sue Helser, ACM Member                                      Alex Steele, ACM Member
Linda Hicks, CSESP Faculty & WebMaster                      Andrew , Steele, ACM Member
Anthony Howell II, CSESP Student                            Nathan Stewart, CSESP Major
Nate Huber, CSESP Student                                   Pat Slackta, CSESP Office Administrator
Vasu Iyengar, MCC Faculty & Judge                           Andrew Thomas, CSESP Alumnus
Kay Jantharasorn, ACM Member                                Steve Turner, CSESP Faculty
Pam Kalmar, CSESP Adjunct                                   Mark Turnpaugh, ACM Member
James Kessler, CSESP Student                                Mojtaba Vaziri, CSESP Faculty
Katie Leist, CSESP Secretary                                Chris Wilson, ACM Officer
Igor Lock, CSESP Student                                    Marc Wojtowicz, Judge
Mark Mercado, ACM Vice-Chair                                Mudasser Wyne, CSESP Faculty & Judge
Rachel Noffsinger, Math Major
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department


                                      Complete List of Sponsors
                        Flint Area School Employees Credit Union

                                 Student Government Council, UM-Flint

                             Office of Institutional Development, UM-Flint

                                                 Help Room

                                      Diversified Insurance Services Ltd.

                              Information Technology Services, UM-Flint

                                       University Relations, UM-Flint

                                            Print Shop, UM-Flint

                                  UM-Flint Student Chapter of the ACM

         Computer Science, Engineering Science, and Physics Department, UM-Flint
UM-F Student Chapter of the                                                  2006 High School Programming Contest
Association for Computing Machinery                   Computer Science, Engineering Science, and Physics Department



                              Important Note to All Contestants

ALL CONTESTANTS
General note regarding printouts:
 If you want a printout of your program for debugging (or other) purposes, make a copy of the program
   on the floppy provided to you, fill out a "printout request form" and give it to a monitor. A printout
   will be supplied to you as soon as possible.

General note regarding data files:
 If you are using any language other than QBASIC, you MUST create your own data file in order to test
   your program. You can create this data file using the QBASIC (or any other) editor and saving the file
   in C:\ under the name xyz.TXT. Here xyz is the name that you have been asked to use for the problem.
 There is no data file needed for QBASIC programs. Just type in the input data in DATA statements.


QBASIC PROGRAMMERS
Input data:
 Use ONLY READ/DATA statements to read the input data.
 Use DATA statement to incorporate in your program any data you want to test your program on.
 ****** DO NOT PROMPT THE JUDGES FOR THEIR DATA! ******
 The judges will automatically incorporate their own data into your program before they judge it.

Output:
 When you submit your program for judging, output should ALWAYS be to a clear screen.
 This means always use PRINT. Don’t use LPRINT or PRINT #1.



C++ PROGRAMMERS
 See the separate sheets for the important special instructions you need to follow.

VISUAL BASIC PROGRAMMERS
 See the separate sheet for the important special instructions you need to follow.
    UM-F Student Chapter of the                                                    2006 High School Programming Contest
    Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department


                                     INSTRUCTIONS FOR
                                  Turbo C++ PROGRAMMERS
    If you are using Turbo C++ it is important that you follow the instructions given below to write your
    program as well as to submit your program for judging. Throughout these instructions, we will assume that
    the name of the program that you have been asked to use in solving the problem is: xyz. You will, of
    course, need to modify this name appropriately as specified by the problem statement.

    General :
     It is your responsibility to include the appropriate #include‟s
     ALL files must be saved in the C:\ directory using the name given for the problem.
     When you are ready to submit, make sure to submit xyz.cpp.

    DATA FILE FOR YOUR Turbo C++ PROGRAM
     You need to create your own data file in C:\xyz.TXT to test your Turbo C++ program. You can use
      the Turbo C++ editor or QBASIC editor to do this.
     It is your responsibility to open and close this data file C:\xyz.TXT.
     It is your responsibility to read the data appropriately from this file.
     For your reference, 2 examples of reading from a file in Turbo C++ are provided below.

    OUTPUT OF YOUR Turbo C++ PROGRAM
     The output of your Turbo C++ program must ALWAYS be on a clear screen.
     This means always use cout.
     DO NOT make any references to files in your output.

    2 EXAMPLES FOR READING DATA FILES IN Turbo C++:

        To read 2 entire lines of data which are each not more than 80 characters long:
    char A[81], B[81]; //strings A and B are no longer than 80 chars
    ifstream inpfile("C:\\xyz.TXT'');
    inpfile.getline(A, 81, ‘\n’); //read the 1st line of the data file into the string variable A
    inpfile.getline(B, 81, ‘\n’); //read the 2nd line of the data file into the string variable B
    inpfile.close();

         To read 3 pieces of data from one line of the data file when data are blank separated:
    char A[81]; //for a string that is not more than 80 characters long
    int B;
    double C;
     ifstream inpfile("C:\\xyz.TXT'');
    inpfile >> A >> B >> C; //read the 1st data item as a string, the 2nd as int and the 3rd as double
                                //respectively into the variables A, B, and C.
    inpfile.close();
    UM-F Student Chapter of the                                                   2006 High School Programming Contest
    Association for Computing Machinery                    Computer Science, Engineering Science, and Physics Department


                                     INSTRUCTIONS FOR
                                  Visual C++ PROGRAMMERS
    If you are using Visual C++ it is important that you follow the instructions given below to write your
    program as well as to submit your program for judging. Throughout these instructions, we will assume that
    the name of the program that you have been asked to use in solving the problem is: xyz. You will, of
    course, need to modify this name appropriately as specified by the problem statement.

    General :
     It is your responsibility to include the appropriate includes.
     ALL files must be saved in the C:\ directory using the name given for the problem.
     When you are ready to submit, make sure to submit ALL the files (xyz.*) generated by the
       system.

    DATA FILE FOR YOUR Visual C++ PROGRAM
     You need to create your own data file in C:\xyz.TXT to test your Visual C++ program. You can use
      the Turbo C++ editor or QBASIC editor to do this.
     It is your responsibility to open and close this data file C:\xyz.TXT.
     It is your responsibility to read the data appropriately from this file.
     For your reference, 2 examples of reading from a file in Visual C++ are provided below.

    OUTPUT OF YOUR Visual C++ PROGRAM
     The output of your Visual C++ program must ALWAYS be on a clear screen.
     This means always use cout.
      DO NOT make any references to files in your output.

    2 EXAMPLES FOR READING DATA FILES IN Visual C++:
    (note: the Turbo C++ example given above can also be used in Visual C++)

        To read 2 entire lines of data which are not more than 80 characters long
    string A, B;
    ifstream inpfile("C:\\xyz.TXT'');
    getline(inpfile, A); //read the 1st line of the data file into the string variable A
    getline(inpfile, B); //read the 2nd line of the data file into the string variable B
    inpfile.close();

         To read 3 pieces of data from one line of the data file when data are blank separated
    string A;
    int B;
    double C;
     ifstream inpfile("C:\\xyz.TXT'');
    inpfile >> A >> B >> C; //read the 1st data item as a string, the 2nd as int and the 3rd as double
                               //respectively into the variables A, B, and C.
    inpfile.close();
    UM-F Student Chapter of the                                                    2006 High School Programming Contest
    Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department


                                  INSTRUCTIONS FOR
                             VISUAL BASIC PROGRAMMERS
    If you are using Visual Basic to solve a problem, it is important that you follow the special instructions
    given below to write your program as well as to submit your program for judging. Throughout these
    instructions, we will assume that the name of the program that you have been asked to use in solving the
    problem is: xyz.*. You will, of course, need to modify this name appropriately as specified by the
    problem statement.

    USING FORMS/MODULES/PROJECTS :
     DO NOT use more than 1 form in each project. DO NOT USE ANY MODULES.
     ALL files must be saved in the C:\ directory using the name given for the problem.

    DATA FILE FOR YOUR VB PROGRAM
     You need to create your own data file in C:\xyz.TXT to test your VB program.
     It is your responsibility to open and close this data file C:\xyz.TXT.
     It is your responsibility to read the data appropriately from this file.
     For your reference, 2 examples of reading from a file in VB are provided below.

    OUTPUT OF YOUR VB PROGRAM
     You can display your answer either in a TEXT BOX or a LIST BOX
     Make sure to put a label with the caption "Answer" above your answer box to indicate to the judges
      that your answer is displayed there.
     If you so choose, you can also include a command button on your form for the judges to click on to run
      your program. Or you can have the program be automatically executed when the form is loaded.
     Remember that the correct answer may consist of one line or several lines.

    2 EXAMPLES FOR READING DATA FILES IN VISUAL BASIC:

       To read 2 entire lines of data
    Dim A, B as string
    Open "C:\xyz.TXT'' For Input As #1
    Line Input #1, A          „read the 1st line of the data file into the string variable A
    Line Input #1, B          „read the 2nd line of the data file into the string variable B
    Close #1

       To read 3 pieces of data from one line of the data file when data are comma separated
    Dim A as string
    Dim B as integer
    Dim C as single
    Open "C:\xyz.TXT'' For Input As #1
    Input #1, A, B, C „read the 1st data item as a string, the 2nd as integer and the 3rd as single
    Close #1          „respectively into the variables A, B, and C
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department




                                                                       Clarifications




                                                         Problem Submission




                                                                      Problem Viewer
          Applications Available for Use




                                                                             Waiting “Private” Clarifications




                                      Main Contest Screen
From this screen, you have the ability to submit solutions for problems, view the current problem-set, and
view any clarifications or messages posted to the contest “message” board. The compilers and programs
available for you to use during the contest are shown on the left hand side of the screen through the use of
the labeled command buttons.
UM-F Student Chapter of the                                                   2006 High School Programming Contest
Association for Computing Machinery                    Computer Science, Engineering Science, and Physics Department




                 Click on an Item for Details




                                                                                        Question and Answer




                                      Clarification Screen
You have the ability to submit a question/comment, and when a judge responds the message will be
available for viewing. A new clarification is created by selecting “NEW” and entering the subject of the
clarification and body of the question to be submitted. If the judge determines that the question needs a
private answer, this answer is indicated by the mailbox indicator on the main contest screen.
UM-F Student Chapter of the                                                     2006 High School Programming Contest
Association for Computing Machinery                      Computer Science, Engineering Science, and Physics Department




                   Submission History
                                                                                                     File Selection




           History Results Appear Here
                                                                                     Directory Selection




                                                           Select Problem Here




                                       Submission Screen
This screen is used to perform all submission operations and serves as a status screen for providing
feedback on the results of a problem submission. To view the status/results of a previous submission, select
the problem from the “Submitted Problems” window. The details for the selection will appear in the
“Submission Details” display. The filter radio buttons may be used to filter the items appearing in the
submitted problems window.

To submit a solution:
     1. First select the files needed for your solution to run correctly. (Select multiple files by holding the
        CTRL key and clicking on the files in the file selection display.)
     2. Then select the problem for which you are submitting the solution from the drop down listing.
     3. Click submit and verify the information in the dialog box. Upon selecting OK, your solution is
        submitted for judging.

NOTE: It is your responsibility to ensure that every file needed for accurate judging is selected prior to
submission. You should also double check the problem you selected from the drop down selection list.
QBASIC and Turbo C++ programs require exactly one file to be submitted (.BAS or .CPP); For VB and
VC++ it is safest to select and submit the source files (.cpp, .frm) AS WELL AS ALL the other files the
system generates.
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department


Responses to submissions

When a problem has been judged, it is either accepted or rejected. If the problem is accepted, the
submission time (plus any accumulated penalty) will be added to the score board and the team will be
notified.

If the problem is rejected, one of the following errors seen by the judges will be notified to the team. Note
that NOT all errors will necessarily be listed.

         The Program Did Not Compile Properly
         An error occurred after the program was running
         Program Exceeded 2 minute execution time
         Output was incorrect
         There was too much or too little output
         The answers were correct, but not in the required format
         Corrections to the problem have been posted and the team must read the clarification to correct the
          program according to the posting.

How the scoring is done

For every accepted problem, the score is equal to the time (in seconds) from the start of the contest plus
1200 times the number of previous incorrect submissions for that problem. (1200 denotes a 20 minute
penalty for each wrong submission). The team with the maximum number of correctly solved problems is
the winner. For two teams with the same number of correctly solved problems, the one with the smaller
score is the winner.




            The Decision of the Contest Director is Final in all
                  Matters Pertaining to This Contest
UM-F Student Chapter of the                                                        2006 High School Programming Contest
Association for Computing Machinery                         Computer Science, Engineering Science, and Physics Department




             List of participating schools, coaches, and their teams
 school & coach         team 1              team 2                    team 3                team 4
 Canton                 Dan Anthony         Kathy Lu
 Ron Carlson            Pat Southern        Willa Chen
                        Alexis Reyes        Amy Shen


 Clarkston HS           Mike Bell           Jesse Livezey             Bryan Culver
 Ron Conwell            Mike Auchter        Evan Dougherty            Kevin McKean
                        Chris Hammond       Jeff Monroe               Richard Pokrefky


 Cranbrook              Bohao Pan

 Rich Lamb              Thaddeus Cybulski
                        John Thomas


 Davison                Rob Blanckaert      Thomas Stockwell
 Josh Wallberg          David Burwell       Ryan Everson
                        Zach Church         Michael Haggerty

 H.H.Dow                Jill Doty           Ed Daugs                  Michael Starch
 Suzanne
 Ostahowski             Lisa Stibitz        Sam Lewia                 Tim Shi
                        Ryan Wilson         Richie Main               Charlie Stibitz

 KAMSC                  Jesse Denardo       Sean Boyle                Tom Brown             Omar Abudayyeh
 Shannon Houtrouw       David Hanley        Dan Cox                   Nate Hinkle           Charles Chu
                        Ben King            Brian Gilbert             Michael Hayter        Evan Fischell


 Midland                Michael Vo          Julie Mitchell            JT Plotzke            Kelson Reiter
 Bob Fox                Dan Holycross       Scott High                Logan Matthews        Patrick Sandoval
                        Sherwood Wang       Jacob Oberlin             Jake Novak            Richard Pringle

 Northville             Matt Gray
 Cheri Sclater          Ishaan Sandhu
                        Jay Zawrotny

 Plymouth               Jake Pozanski       Brian Schmeider           Sarah Trombley
 Ron Carlson            John Palgut         Eric Gilson               Ted Wakar
                        Chris Grelik        Andrew Hagen              Wendell West


 Salem                  Eric Marion
 Karen Palgut           Kurt Seippel
                        Adam Clark
UM-F Student Chapter of the                                              2006 High School Programming Contest
Association for Computing Machinery               Computer Science, Engineering Science, and Physics Department




                                      The Contest Problem Set
                   The following pages contain the six contest problems and one
                    solution in VC++ 6.0. Also included are the judges‟ data.
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                      Computer Science, Engineering Science, and Physics Department
Problem #1: String Arithmetic
Call this program:
QBASIC: arith.bas                     VB: arith.*           TC++: arith.cpp                        VC++: arith.*

Consider a string of text which has embedded in it integers and operators. The integers may be positive or
negative or zero. The only operators of interest in this problem are: plus (+), minus (-) and multiplication
(*). All other characters (including the decimal point) in the string should be considered as characters that
separate the integers and the operators.

Reading the string from left to right, you will "extract" the integers and operators in turn starting with the
FIRST integer, then alternately extracting the FIRST available operator to the right, then the FIRST
available integer to the right, etc. and ending with the LAST available integer as follows:

integer1 operator1 integer2 operator2 ... last_integer
and then evaluate the resulting expression from left to right.

Since the minus sign (-) can be interpreted as a subtraction operator or the negative sign for the next integer,
the following convention is used. When you are looking for an integer, a minus sign IMMEDIATELY
before an integer (without any separating characters between them) makes the integer negative. However,
when you are looking for an operator, the minus sign should always be treated as a subtraction operator
even if it is immediately before an integer.

Note that you will evaluate the resulting expression from LEFT TO RIGHT. DO NOT use the usual
operator precedence rules (e.g., multiply before adding or subtracting). You are not told how many integers
and operators you will end up extracting from the input string, but you are guaranteed to extract at least one
integer and for every operator you do extract, there will always be an integer to the right you should extract.
The entire length of the initial input string will not exceed 80 characters and there will not be more than 10
operators you will need to deal with on one input string.

Below are several examples with explanations:

string: "abc- 17def - - 18 ghAB25Cm-hAB -19abcDEFg"
expression: 17 - 18 - -19
value: 18
comment:
          integer1 is 17 and not -17 because there is a separator.
          integer2 is 18 for the same reason.
          25 does not come into play since you are looking for an operator.
          integer3 is -19 because you are looking for an integer.

string: "abc-17de25f -18.27 gh&$,;m-19abcdefg"
expression: -17 - 18 - 19
value: -54
comment:
          integer2 is 18

string: "**++- - - ab-17abc 126de- -18 ghm-*19abgh*ABC-10k12rs*+++++++----***abc- 100"
expression: -17 - -18 - 19 * - 10 * 100
value: 18000
comment:           integer2 is -18
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                      Computer Science, Engineering Science, and Physics Department


Input format:
There will be exactly 4 of lines of input. Each line will be a problem string that you will process.

Output format:
You will display exactly 4 lines of output where each line will be the result of your calculation.

Sample input for QBASIC:
DATA "abc- 17def - - 18 ghAB25Cm-hAB -19abcDEFgh"
DATA "c-10de25f * - 18 gh&$,;m-19abcdefg"
DATA "**++- - - ab-2abc 126de- - 1 ghm-*19abgh*ABC-10k12rs*+++++++----**bc-                      100"
DATA “10*20-150”

Sample data file for VB: (c:\arith.txt)
"abc- 17def - - 18 ghAB25Cm-hAB -19abcDEFgh"
"c-10de25f * - 18 gh&$,;m-19abcdefg"
"**++- - - ab-2abc 126de- - 1 ghm-*19abgh*ABC-10k12rs*+++++++----**bc-                  100"
 “10*20-150”

Sample data file for Turbo C++ and VC++: (c:\arith.txt)
abc- 17def - - 18 ghAB25Cm-hAB -19abcDEFgh
c-10de25f * - 18 gh&$,;m-19abcdefg
**++- - - ab-2abc 126de- - 1 ghm-*19abgh*ABC-10k12rs*+++++++----**bc-                 100
10*20-150

Note:
The data for QBASIC and VB are enclosed in double quotes but the data for C++ are not.

Corresponding Output:
18
-199
22000
50
UM-F Student Chapter of the                                                   2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department
Problem #2: Derivative of a Polynomial
Call this program:
QBASIC: poly.bas                      VB: poly.*          TC++: poly.cpp                          VC++: poly.*

Definitions:
In the following “number” refers to ONE digit positive or negative integer.
A term is of the form:    number1*x^number2 where ^ is read as "to the power."
Note that: x^0 =1.

number1 is usually called the coefficient and number 2 is usually called the exponent.

When the coefficient is 0, the term is not shown at all.
When exponent is 0, the term is shown merely as the coefficient.
When coefficient is 1 and exponent is not 0, coefficient is not explicitly shown in the term.
When coefficient is -1 and exponent is not 0, coefficient is shown as just a negative sign.
When exponent is 1, x^1 is shown merely as x.
Finally no multiplication sign (*) is shown at all.

A polynomial is one or more terms which are added and/or subtracted. If all the coefficients are 0, the
polynomial is displayed as 0.

Here are examples of three polynomials:
3x^7-2x^5+7x-19
5x+x^2-2
-x^3+1

The derivative of the term number1*x^number2 is number1*number2*x^(number2-1). The
derivative of a term which has no x in it is 0. The derivative of a polynomial is the derivative of its
individual terms added and/or subtracted as appropriate.

Here are the derivatives of the above example polynomials displayed as indicated above:
21x^6-10x^4+7
5+2x
-3x^2

In this problem, you will be given a polynomial and an integer value for x, and you will display the integer
value of the derivative of the polynomial at the given value of x.

Notes:
There will not be more than 10 terms in any polynomial.
There will be no blank spaces in the input polynomial.
No input string will be more than 40 characters long.
The coefficients and exponents in the input will all be single digit numbers (0 to 9). Coefficients may
be negative but not the exponents.
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department


Input format:
There will be exactly 4 lines of input. Each line will provide an integer (a) followed (after a single blank) by
a polynomial.

Output format:
The output should be exactly 4 lines where each line containing an integer denoting the value of the
derivative at x=a.

Sample input for QBASIC:
DATA 1, 2x^7+x^2+3x-9
DATA -3, 5
DATA 10, -5x^2+x^3+1
DATA -5, -8x+4x

Sample data file for VB: (c:\poly.txt)
1, 2x^7+x^2+3x-9
-3, 5
10, -5x^2+x^3+1
-5, -8x+4x

Note the delimiting comma between the value of x and the polynomial in the above.

Sample data file for Turbo C++ and VC++: (c:\poly.txt)
1 2x^7+x^2+3x-9
-3 5
10 -5x^2+x^3+1
-5 -8x+4x

Note the blank between the value of x and the polynomial.

Corresponding Output:
19
0
200
-4
UM-F Student Chapter of the                                                   2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department
Problem #3: Word Meanings

Call this program:
QBASIC: meanings.bas          VB: meanings.*           TC++: meanings.cpp            VC++: meanings.*

You will write a program that can print meanings of many variations of a small handful of different root
words. You do this by recognizing common prefixes and suffixes. Your program should be able to
recognize up to one prefix and up to one suffix per word.

You will need to deal with only the following 5 valid prefixes: anti, post, pre, re, un. Their meanings with
examples are given below:

prefix          meaning               example word        meaning
======          =======               ============        ===================
anti<word>      against <word>        antiwar             against war
post<word>      after <word>           postwar             after war
pre<word>       before <word>          prewar      before war
re<word>        <word> again           rewar       war again
un<word>         not <word>            unwar       not war

You will need to deal with only the following 5 valid suffixes: er, ing, ize, s, tion. Their meanings with
examples are given below:

suffix        meaning                        example word        meaning
======        =======                      ==========            ===================
<word>er      one who <word>s                fighter             one who fights
<word>ing     to actively <word>             fighting            to actively fight
<word>ize     change into <word>             legalize            change into legal
 <word>s      multiple instances of <word> fights                multiple instances of fight
<word>tion    the process of <word>ing      adoption             the process of adopting

Note that if the example word has BOTH a prefix and a suffix, the prefix should be processed first and
THEN the suffix. For example, the words "unvaporize" and “repairer” would be expanded through the
following steps:
unvaporize
not vaporize
not change into vapor

repairer
pairer again
one who pairs again

If the example word has no prefix and no suffix, the meaning will be the same as the given word. Finally,
for each word, you need to process a maximum of only one prefix and one suffix.
UM-F Student Chapter of the                                                   2006 High School Programming Contest
Association for Computing Machinery                     Computer Science, Engineering Science, and Physics Department


Input format:
Input will be a single line of text containing exactly 6 words. The words in the line will be separated by
exactly a single space.

You need to identify the words and then identify the prefix and suffix (if any) and expand them as indicated
above. You don't need to expand more than one prefix. You don't need to expand more than one suffix. No
input word will be longer than 25 characters.

Output format:
For each word in the input, output the meaning by replacing the prefix and/or suffix as described above.
The words should be displayed in the same order as they appear in the input line. Display one expanded
meaning per line.

Sample input for QBASIC:
DATA vaporize, prewar, recooking, root, repopularize, uninforming

Sample data file for VB, Turbo C++ and VC++: (c:\meanings.txt)
vaporize, prewar, recooking, root, repopularize, uninforming

Note in the above the words are separated by commas.

Sample data file for Turbo C++ and VC++: (c:\meanings.txt)
vaporize prewar recooking root repopularize uninforming

Note that the data words for C++ are separated by single blanks.


Corresponding Output:
vaporize = change into vapor
prewar = before war
recooking = to actively cook again
root = root
repopularize = change into popular again
uninforming = not to actively inform
UM-F Student Chapter of the                                                  2006 High School Programming Contest
Association for Computing Machinery                    Computer Science, Engineering Science, and Physics Department
Problem #4: Digital Alarm Clock
Call this program:
QBASIC: alarm.bas VB: alarm.*                 TC++: alarm.cpp         VC++: alarm.*

Rocky rolled over in his bed and looked at his LED alarm clock. He saw what was displayed and went back
to sleep. Later, he woke up again and once again glanced at the alarm clock. Although he did not know if all
the LED segments were actually working, this second time he was able to determine the exact time. Could
you?

Rocky's LED clock uses the usual four 7-segment displays to show the time. Each 7-segment display has
seven bars (3 horizontal bars and 4 vertical bars) on it, and displays different numbers by "turning on"
different bars as below:




Using one bit to represent each segment, we can describe a display with seven bits. For example, the
display:




can be represented with the bit sequence: 0000111.

The numbers from 0 to 9 can be represented as shown on the next page: (1 represents that the bit is ON)

Number         Bit 1        Bit 2     Bit 3   Bit 4       Bit 5         Bit 6       Bit 7
0              1            1         1       1           1             1           0
1              0            1         1       0           0             0           0
2              1            1         0       1           1             0           1
3              1            1         1       1           0             0           1
4              0            1         1       0           0             1           1
5              1            0         1       1           0             1           1
6              1            0         1       1           1             1           1
7              1            1         1       0           0             0           0
8              1            1         1       1           1             1           1
9              1            1         1       1           0             1           1
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                      Computer Science, Engineering Science, and Physics Department


However, if any segment on the display is "burnt out", it will not display even though it should. For
example, if the number 3 were to be displayed, but the segments corresponding with bit 7 and bit 1 were
burnt out, the display would instead be:




Input format:
There will be exactly 2 lines of input. Each line is one problem set. Each line contains eight 7-bit strings
representing the LED displays that Rocky observed. The first four strings will represent the first-time
display and the last four strings will represent the second-time display. All of the strings will be separated
by exactly single spaces between them.
Note: It is not given in the input which (if any) segments are burnt out.

Output format:
There will be exactly two lines of output. Each line will simply be the second-time observed time in the
LED display, in the format HH:MM.

You can assume that the segments that are burnt out don't change from the first observation to the second
observation. There will only be one possible solution for each data set. All times (for input and output) will
be represented in standard (non-military) format. For example, nine o'clock is 09:00, midnight is 00:00 and
noon is 12:00.

Sample input for QBASIC:
DATA 0010000, 1101101, 1111110, 1111111, 1010000, 1111011, 1111110, 1111111
DATA 1100000, 0010000, 1000001, 1111111, 0100000, 0000001, 0000000, 0110000

Sample data file for VB: (c:\alarm.txt)
0010000, 1101101, 1111110, 1111111, 1010000, 1111011, 1111110, 1111111
1100000, 0010000, 1000001, 1111111, 0100000, 0000001, 0000000, 0110000

(Note: Since comma is the data delimiter for QBASIC and VB, data in the above are separated by
commas)

Sample data file for Turbo C++ and VC++: (c:\alarm. txt)
0010000 1101101 1111110 1111111 1010000 1111011 1111110 1111111
1100000 0010000 1000001 1111111 0100000 0000001 0000000 0110000

(Note: Since blank is the data delimiter for C++, data in the above are separated by blanks)

Corresponding Output:
09:08
12:11
UM-F Student Chapter of the                                                    2006 High School Programming Contest
Association for Computing Machinery                      Computer Science, Engineering Science, and Physics Department
Problem #5: Bus Ride
Call this program:
QBASIC: bus.bas          VB: bus.*             TC++: bus.cpp            VC++: bus.*

You decide to take the bus to visit a friend in the next town. The problem is that the bus station you are at
has the world's worst bus schedule! In fact, there are no arrival or departure times listed; only route
durations for each bus running. Being the impatient person that you are, you whip out your laptop and
attempt to write a program that will determine how long you will have to wait before the next bus comes in.
Background info:
There are a number (N) of buses to your destination.
Each bus has a number (M) of routes to your destination that are "used" as follows: the bus takes the first
route to your destination and returns to your bus station, then turns around and goes to the destination using
second route and returns to the station and then takes the third route and so on. After exhausting all the M
routes in the order given, it starts all over again with the first route and continues in this fashion.

Your task is to determine the shortest waiting time for you to catch the next bus. And also to determine
which bus it is.

Input format:
The first line of input will be a single integer N (between 1 and 20) indicating the number of buses running
to your destination.
Each of the next N lines will be of the form: B M r1 r2 r3 ... rM
where B=bus number
          M=number of routes for the bus B
          r1 r2 ... rM (in this order) = the roundtrip times for the bus B to return to your
                     bus station after going through its route. R1 is the first route for this bus,
                     r2 is the second route etc.
The last line of input is a single integer denoting the time of your arrival at the bus station.

Note:
All data are positive integer.
All of the buses start their run for the day at time = 0
If your arrival time at the bus station coincides with the return time of any bus, then your shortest waiting
time is 0 and you take that bus.

Output format:
Your output should be a single line with 2 numbers separated by one blank space. The first number is the
bus number (B) and the second number is the shortest waiting time to catch that bus. If the shortest waiting
time happens to be the same for more than one bus, output any one of these results.

Two sample problems and answers:
Example 1:
3
20 3 100 200 300
100 3 400 500 600
75 3 700 800 900
1000
UM-F Student Chapter of the                                             2006 High School Programming Contest
Association for Computing Machinery               Computer Science, Engineering Science, and Physics Department


Corresponding output:
20 200

Example 2:
4
12 9 100 200 300 4 3 2 4 2 22
33 1 800
99 5 100 100 100 100 100
45 2 10 1000
32767

Corresponding output:
12 20

Sample input for QBASIC:
DATA 3
DATA 20, 3, 100, 200, 300
DATA 100, 3, 400, 500, 600
DATA 75, 3, 700, 800, 900
1000

Sample data file for VB: (c:bus.txt)
3
20, 3, 100, 200, 300
100, 3, 400, 500, 600
75, 3, 700, 800, 900
1000

(Note: Since comma is the data delimiter for QBASIC and VB, in the above data are separated by
commas)



Sample data file for Turbo C++ and VC++: (c:\bus. txt)
3
20 3 100 200 300
100 3 400 500 600
75 3 700 800 900
1000
(Note: Since blank is the data delimiter for C++, data in the above are separated by
blanks)
Corresponding Output:
20 200
UM-F Student Chapter of the                                                        2006 High School Programming Contest
Association for Computing Machinery                          Computer Science, Engineering Science, and Physics Department


Problem #6: Virtual Computer
Call this program:
QBASIC: virtual.bas                   VB: virtual.* TC++: virtual.cpp       VC++: virtual.*

Below is a table with two columns. For each row, column 1 denotes a computer command followed by its
parameters. Column 2 explains the meaning of the command in column 1.

               Command                                                        Explanation
                                             Will set variable <x>'s value to <value>
SET <x> <value>
                                             Example: SET a 9              is equivalent to a = 9
                                             Will set variable<y>'s value to the value of variable <x>
STORE <x> <y>
                                             Example: STORE b a            is equivalent to a=b
                                             Same as variable <x> = variable <x> * variable <y>
MULT <x> <y>
                                             Example: MULT b a           is equivalent to b = b * a
                                             Same as variable <x> = variable <x> - variable <y>
SUB <x> <y>
                                             Example: SUB b c            is equivalent to b = b - c
                                             Equivalent to variable <x> = variable <x> + variable <y>
ADD <x> <y>
                                             Example: ADD b c             is equivalent to b = b + c
                                             Displays the value of the variable <x> and moves to the next line.
PRINT <x>
                                             Example: PRINT b

NOTE: All variables and all calculations are of type integer.

Input format:
The first line of input will be a single integer N denoting the number of commands that follow - one on each
line.

         All variables are initialized with a SET command before being used.
         All variables are single lowercase letters (a, b, c, ..., z).
         All variable values will be integers.
         Arguments to individual commands will always be separated by EXACTLY one space.

Output format:
The output will be the result of the program. PRINT commands are the only ones which generate output.
There should be as many lines of output as there are PRINT commands that are executed.

Two sample problems and answers:
Example 1:
2
SET b 10
PRINT b

Corresponding output:
10
UM-F Student Chapter of the                                             2006 High School Programming Contest
Association for Computing Machinery               Computer Science, Engineering Science, and Physics Department


Example 2:
6
SET b 10
SET a 2
SET x 0
STORE a x
MULT x b
PRINT x

Corresponding output:
20

Sample input for QBASIC:
DATA 10
DATA SET a 1
DATA SET b 2
DATA SET c 3
DATA SET d 4
DATA SET e 5
DATA STORE e a
DATA ADD a a
DATA PRINT a
DATA MULT c b
DATA PRINT c

Sample input for all others VB, Turbo C++ and VC++: (c:\virtual.txt)
10
SET a 1
SET b 2
SET c 3
SET d 4
SET e 5
STORE e a
ADD a a
PRINT a
MULT c b
PRINT c

Corresponding output:
10
6
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department
Solution #1: String Arithmetic
//includes
#define MAX 10
string digits="0123456789";
string operators="+-*";

int string2number(string &s) {
  int ndx=s.find_first_of(digits);
  if ( (ndx>0) && (s.substr(ndx-1,1)=="-") ) ndx=ndx-1;
  s=s.substr(ndx, -1);
  int num=atoi(s.c_str());
  if (s.substr(0,1)=="-") s=s.substr(1, -1);
  //cout << s << "\n" << num << endl;
  return num;
}
string string2op(string &s) {
  int ndx=s.find_first_of(operators);
  if (ndx>=s.length()) { s=""; return s; }
  else {
      string op=s.substr(ndx, 1); s=s.substr(ndx+1, -1);
      return op;
  }
}
void readfile(string s[MAX]) {
  ifstream inf;
  inf.open("c:\\arith.txt");
  if(!inf) cout << "file problem\n";
  for (int i=0; i<4; i++) getline(inf, s[i], '\n');
  inf.close();
}
void main() {
      system("cls");
      int num1, num2, i;       string op1, st, sarr[MAX];
      readfile(sarr);
      for (i=0; i<4; i++) {
         st=sarr[i];
         num1=string2number(st);
         cout << num1 << " " ;
         op1=string2op(st);
         while(st!="") {
           num2=string2number(st);
           cout << op1 << " " << num2 << " " ;
           if (op1=="+") { num1=num1+num2; }
           if (op1=="-") { num1=num1-num2; }
           if (op1=="*") { num1=num1*num2; }
           op1=string2op(st);
         }
         cout << " = " << num1 << endl;
      }
}

//judges data:
1 - 1 16 17 18 19 20
George wash-22was the first*president35*in seventeen-10seventy six
- this 10-/number222.78but +-*one is 3033-this.10000plus+five5six
*product of -7and another *- -90 is one thousand
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

//answers
1-1 =0
-22*35*-10 = 7700
10-222+3033-10000+5 =-7174
-7*-90 =63
UM-F Student Chapter of the                                     2006 High School Programming Contest
Association for Computing Machinery       Computer Science, Engineering Science, and Physics Department
Solution #2: Derivative of a Polynomial
//includes
#define MAX 10
string poly, terms[MAX];

int poly2terms() {
  string ops="+-", temp; int cnt=0, start, ndx;
  while (poly!="") {
    start=0;
    if ( (poly.substr(0,1)=="-") || (poly.substr(0,1)=="+") ) start=1;
      if (start==0) {
        ndx=poly.find_first_of(ops);
        if (ndx<poly.length()) {
             terms[cnt]=poly.substr(0,ndx); cnt++;
             poly=poly.substr(ndx, -1);
        }
        else { terms[cnt]=poly; cnt++; poly=""; }
      }
      else {
        temp=poly.substr(1,-1);
      ndx=temp.find_first_of(ops);
      if (ndx<temp.length()) {
          terms[cnt]=poly.substr(0,ndx+1); cnt++;
          poly=poly.substr(ndx+1, -1);
        }
        else {terms[cnt]=poly; cnt++; poly="";}
    }
  }
  return cnt;
}
void term2coef_exp(string term,int &coef, int &exp) {
  if (term.rfind("x") >term.length() ) {
    coef=atoi(term.c_str()); exp=0;
  }
  else if (term.rfind("^") >term.length() ) {
      exp=1;
    if (term.length()==1) coef=1;
      else if (term.length()>=3) coef=atoi(term.c_str());
      else {
      if (term[0]=='-') coef=-1;
        else if (term[0]=='+') coef=1;
        else coef=atoi(term.c_str());
      }
  }
  else { //both x^ are there
      string temp=term.substr(term.length()-1, 1);
    exp=atoi(temp.c_str());
      int ndx=term.find("x");
      if (ndx==0) coef=1;
      else {
        term=term.substr(0, ndx);
        if (term=="-") coef=-1;
        else if (term=="+") coef=1;
        else coef=atoi(term.c_str());
      }
  }
}
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

int eval_der_term(int coef, int exp, int x0){
   if (exp==0) return 0;
   else       return coef*exp*pow(x0,exp-1);
}
void main() {
   int val=0, i, x, cnt, coef, exp, derval=0;
   ifstream inf;
   inf.open("c:\\poly.txt");
   if(!inf) {cout << "file error\n"; exit(0); }
   for (int k=0; k<4; k++) {
     inf >> x >> poly;
     //cout << poly << endl ;
     cnt=poly2terms();
        derval=0;
     for (i=0; i<cnt; i++) {
        term2coef_exp(terms[i],coef, exp);
        val= eval_der_term(coef, exp, x);
          derval=derval+val;
        }
     cout << derval << endl;
   }
}
//judges data
2 -3x^3-4x^6+4x-7+8x^7
-1 4x^2+8x+1
0 5x^2-3x^2+4x^3-7x
-2 x^6+x^4+x^2+3x
//answers
2784
0
-7
-225
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department
Solution #3: Word Meanings
//includes
#define MAX 10

string prefix[5]={"anti", "post", "pre", "re", "un"};
string suffix[5]={"er", "ing", "ize", "s", "tion"};
int flen[MAX]={4, 4, 3, 2, 2, 0};
int Llen[MAX]={2, 3, 3, 1, 4, 0};

void get_prepost( string x, int &f, int &L) {
  string pref=x.substr(0,4);
  if(x.substr(0,4)=="anti") f=0;
  else if(x.substr(0,4)=="post") f=1;
  else if(x.substr(0,3)=="pre") f=2;
  else if(x.substr(0,2)=="re") f=3;
  else if(x.substr(0,2)=="un") f=4;
  else f=5;
//post
  int len=x.length();
  if (x.substr(len-2,2)=="er") L=0;
  else if (x.substr(len-3,3)=="ing") L=1;
  else if (x.substr(len-3,3)=="ize") L=2;
  else if (x.substr(len-1,1)=="s") L=3;
  else if (x.substr(len-4,4)=="tion") L=4;
  else L=5;
}
string get_root(string x, int prendx, int sufndx) {
  string root;
  root=x.substr(flen[prendx], -1);
  root=root.substr(0, root.length()-Llen[sufndx]);
  return root;
}
string f_process(string x, int f) {
  switch(f) {
       case 5: return x; break;
       case 0: return "against "+ x; break;
       case 1: return "after "+ x; break;
       case 2: return "before "+ x; break;
       case 3: return x+" again"; break;
       case 4: return "not "+ x; break;
  }
  return "error";
}
string L_process(string x, int L) {
  switch(L) {
       case 5: return x; break;
       case 0: return "one who "+ x+"s"; break;
       case 1: return "to actively "+ x; break;
       case 2: return "change into "+ x; break;
       case 3: return "multiple instances of "+x; break;
       case 4: return "the process of "+ x+"ing"; break;
  }
  return "error";
}
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

void main() {
  string x, part1, p1, p2, p3; int f, L, ndx;
  ifstream inf;
  inf.open("c:\\2006progs\\meanings.txt");

    if(!inf) {cout << "file error\n"; exit(0);}
    for(int i=0; i<6; i++) {
      inf >> x;
      get_prepost(x, f, L);
      cout << x << " = ";
      string root=get_root(x, f, L);
        if ( (f==5)&&(L==5) ) { //no processing
              cout << x << endl; continue;
        }
        if (f==5) { //do only suffix
        string Lpart=L_process(root, L); cout << Lpart << endl; continue;
        }
        if (L==5) { //do only prefix
        string fpart=f_process(root, f); cout << fpart << endl; continue;
        }
        //do both
        x=root+suffix[L];
      part1=f_process(x, f);
        ndx=part1.find(x);
        p1=part1.substr(0, ndx);p2=x; p3=part1.substr(ndx+x.length(),-1);
        p2=L_process(root, L);
        cout << p1 +p2 + " "+ p3 << endl;
    }
    inf.close();
}

//judges data
pretender rewards unworthy untending seize postponing
//answers
pretender = before one who tends
rewards = multiple instances of ward again
unworthy = not worthy
untending = not to actively tend
seize = change into se
postponing = after to actively pon
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department
Solution #4: Digital Alarm Clock
//includes
string arr[10]={"1111110","0110000","1101101","1111001","0110011",
                "1011011","1011111","1110000","1111111","1111011"};
string h11, h12, m11, m12; //first-time hh mm
string h21, h22, m21, m22; //second-time hh mm
string h1n, h2n, m1n, m2n; //n means that position is correct

string make_n(string x1, string x2) {
  string temp="0000000";
  for (int i=0; i<7; i++) {
      if ( (x1[i]=='1') || (x2[i]=='1') ) temp[i]='n';
  }
  return temp;
}
int chk_h1n() { //h11, h21, h1n) {
  int cnt1=0; int num, flag, bit, temp;
  for (num=0; num<2; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (h1n[bit]=='n') && (h11[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) cnt1++;
  }
  for (num=0; num<2; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (h1n[bit]=='n') && (h21[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) temp=num;
  }
  if (cnt1>=1) return temp;
  else return -1;
}
int chk_h2n(int h1) {
  int limit=10;
  if (h1==1) limit=3;
  int cnt1=0; int num, flag, bit, temp;
  for (num=0; num<limit; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (h2n[bit]=='n') && (h12[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) cnt1++;
  }
  for (num=0; num<limit; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (h2n[bit]=='n') && (h22[bit]!=arr[num][bit])                ) {
        flag=1; break;}
      }
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

       if (flag==0) temp= num;
   }
   if (cnt1>=1) return temp;
   else return -1;
}
int chk_m1n() { //m11, m12, m1n) {
  int cnt1=0; int num, flag, bit, temp;
  for (num=0; num<6; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (m1n[bit]=='n') && (m11[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) cnt1++;
  }
  for (num=0; num<6; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (m1n[bit]=='n') && (m21[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) temp= num;
  }
  if (cnt1>=1) return temp;
  else return -1;
}
int chk_m2n() { //m12, m22, m2n) {
  int cnt1=0; int num, flag, bit, temp;
  for (num=0; num<10; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (m2n[bit]=='n') && (m12[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) cnt1++;
  }
  for (num=0; num<10; num++) {
    flag=0;
    for (bit=0; bit<7; bit++) {
      if ( (m2n[bit]=='n') && (m22[bit]!=arr[num][bit])                ) {
        flag=1; break;
      }
    }
    if (flag==0) temp= num;
  }
  if (cnt1>=1) return temp;
  else return -1;
}
void main() {
  system("cls");
  ifstream inf;
  inf.open("c:\\2006progs\\alarm.txt");
  if(!inf) { cout << "file error\n"; exit(0); }
  int H1, H2, M1, M2;
  int ncases=2;
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

for (ncases=0; ncases<2; ncases++) {
  inf >> h11 >> h12 >> m11 >> m12 >> h21 >> h22 >> m21 >> m22;
  h1n=make_n(h11, h21); //the n vector for h1
  h2n=make_n(h12, h22); //for h2
  m1n=make_n(m11, m21); //for m1
  m2n=make_n(m12, m22); //for m2
  H1=chk_h1n();
  H2=chk_h2n(H1);
  M1=chk_m1n();
  M2=chk_m2n();
  if ( (H1!=-1)&&(H2!=-1)&&(M1!=-1)&&(M2!=-1) )
    cout << H1 << H2 << ":" << M1 << M2 << endl;
}
} //end of main()

//judges data
0001110 1110000 1011011 1111110 0001110 1110111 0110011 0110010
0101010 1010000 1011010 1110110 0100000 0010000 1111000 1110001
//answers
08:44
11:33
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department
Solution #5: Bus Ride
//includes
#define NBUSES 10
#define NRTES 10

struct STT {
   int busnum, nrtes, rtes[NRTES];
   int wait;
};
int nbuses;
STT stt[NBUSES];
int atime;
void readfile() {
   ifstream inf;
   int i, j;
   inf.open("c:\\2006progs\\bus.txt");
   if(!inf) { cout << "file problem\n"; exit(0); }
   inf>>nbuses;
   for (i=0; i<nbuses; i++) {
     inf >> stt[i].busnum >> stt[i].nrtes;
     for (j=0; j<stt[i].nrtes; j++) inf >> stt[i].rtes[j];
   }
   inf>>atime;
}
void displaydata() {
       int i, j;
   cout << nbuses << endl;
   for (i=0; i<nbuses; i++) {
     cout << stt[i].busnum << " " << stt[i].nrtes << " " ;
     for (j=0; j<stt[i].nrtes; j++) cout<<stt[i].rtes[j]<<" ";
       cout << endl;
   }
   cout << atime << endl;
}
int onebus(int M, int r[NRTES]) {
   int busarrtime=0;
   int i=-1;
   while ( busarrtime<atime) {
     i++; busarrtime+=r[i%M];
   }
   return busarrtime;
}

void sortwait() {
  int i, j; STT temp;
  for (i=0; i<nbuses; i++) {
      for (j=0; j<nbuses-1; j++) {
        if (stt[j].wait>stt[j+1].wait) {
        temp=stt[j]; stt[j]=stt[j+1]; stt[j+1]=temp;
        }
      }
  }
}
UM-F Student Chapter of the                                  2006 High School Programming Contest
Association for Computing Machinery    Computer Science, Engineering Science, and Physics Department
void displaywait() {
  int i;
  for (i=0; i<nbuses; i++) {
    cout << stt[i].busnum << " " << stt[i].wait << endl;
  }
}
void displayans() {
  cout << stt[0].busnum << " " << stt[0].wait << endl;
  int i=1;
  while((i<nbuses) && (stt[i].wait==stt[0].wait)) {
    cout << stt[i].busnum << " " << stt[i].wait << endl;
    i++;
  }
}
void main() {
  system("cls");
  int i;
  readfile();
  for (i=0; i<nbuses; i++)
      stt[i].wait=onebus(stt[i].nrtes, stt[i].rtes)-atime;
  sortwait();
  displayans();
}

//judges       data
5
500 7 11       17   23   29 31 37 41
400 6 12       24   35   10 14 17
300 5 10       15   20   25 30
200 4 23       27   33   41
100 3 11       21   31
1789

//answer:
400 3
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department
Solution #6: Virtual Computer
//includes
int num;
string atoz="abcdefghijklmnopqrstuvwxyz";
int vars[26];
int find_varndx(string x) { return atoz.find(x);}
int find_val(string x) { return atoi(x.c_str()); }

void process_SET(string cmd) {
  string var=cmd.substr(0,1);
  int ndx=find_varndx(var);
  cmd=cmd.substr(2, -1);
  vars[ndx]=find_val(cmd);
}
void process_STORE(string cmd) {
  string var1=cmd.substr(0,1);
  int ndx1=find_varndx(var1);
  string var2=cmd.substr(2,1);
  int ndx2=find_varndx(var2);
  vars[ndx2]=vars[ndx1];
}
void process_ADD(string cmd) {
  string var1=cmd.substr(0,1);
  int ndx1=find_varndx(var1);
  string var2=cmd.substr(2,1);
  int ndx2=find_varndx(var2);
  vars[ndx1]+=vars[ndx2];
}
void process_SUB(string cmd) {
  string var1=cmd.substr(0,1);
  int ndx1=find_varndx(var1);
  string var2=cmd.substr(2,1);
  int ndx2=find_varndx(var2);
  vars[ndx1]-=vars[ndx2];
}
void process_MULT(string cmd) {
  string var1=cmd.substr(0,1);
  int ndx1=find_varndx(var1);
  string var2=cmd.substr(2,1);
  int ndx2=find_varndx(var2);
  vars[ndx1]*=vars[ndx2];
}
void process_PRINT(string cmd) {
  string var1=cmd.substr(0,1);
  int ndx1=find_varndx(var1);
  cout << vars[ndx1]<< endl;
}

string find_what(string &line) {
  if (line.substr(0,3)=="SET") {
        line=line.substr(4, -1); return "SET";
  }
  if (line.substr(0,5)=="STORE") {
        line=line.substr(6, -1); return "STORE";
  }
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

    if (line.substr(0,3)=="ADD") {
          line=line.substr(4, -1); return   "ADD";
    }
    if (line.substr(0,3)=="SUB") {
          line=line.substr(4, -1); return   "SUB";
    }
    if (line.substr(0,4)=="MULT") {
          line=line.substr(5, -1); return   "MULT";
    }
    if (line.substr(0,5)=="PRINT") {
          line=line.substr(6, -1); return   "PRINT";
    }
    return "error";
}

void main() {
   string line="", x, var1, var2; int num;
   ifstream inf;
   inf.open("c:\\virtual.txt");
   if (!inf) { cout << "file problem\n"; exit(0);}
   inf >> num;
   for (int i=0; i<num; i++) {
       inf >> x;
       if (x!="PRINT") {
         inf >> var1 >> var2;line=x + " " + var1 + " "+ var2;
       }
       else { inf >> var1; line=x + " " + var1; }
     string cmd=find_what(line);
       if (cmd=="SET") process_SET(line);
       else if (cmd=="STORE") process_STORE(line);
       else if (cmd=="ADD") process_ADD(line);
       else if (cmd=="SUB") process_SUB(line);
       else if (cmd=="MULT") process_MULT(line);
       else if (cmd=="PRINT") process_PRINT(line);
       else { cout << i << "error in command\n"; exit(0); }
   }
   inf.close();
}
//judges data
18
SET x 5
SET a 8
MULT x a
PRINT a
SET b 7
STORE x b
PRINT b
ADD b x
SUB b a
PRINT b
SET y 4
ADD a b
SUB b x
MULT x y
PRINT a
PRINT b
PRINT x
PRINT y
UM-F Student Chapter of the                                 2006 High School Programming Contest
Association for Computing Machinery   Computer Science, Engineering Science, and Physics Department

//answers
8
40
72
80
32
160
4
UM-F Student Chapter of the                                               2006 High School Programming Contest
Association for Computing Machinery                 Computer Science, Engineering Science, and Physics Department




                                      The Contest Pictures
          You can look at photographs taken at the contest at the following web site:

                              http://www.umflint.edu/csesp/Studnt01.html

                                       and click on the link for

                Fifteenth Annual High School Programming Contest May 5, 2006
UM-F Student Chapter of the                                                         2006 High School Programming Contest
Association for Computing Machinery                          Computer Science, Engineering Science, and Physics Department

                                      This event was put together this year by

                    UM-F Student Chapter of
            The Association for Computing Machinery
                               and
 The Computer Science, Engineering Science, and Physics Department
                                              University of Michigan-Flint


                              and was made possible by generous support from:




                                      Office of the Chancellor

                                Student Government Council

                                      Special Events Committee

                          Office of Institutional Advancement

                                           Office of Research

                              Diversified Insurance Services, Ltd.