• 沒有找到結果。

The Hong Kong Olympiad in Informatics 1997

N/A
N/A
Protected

Academic year: 2021

Share "The Hong Kong Olympiad in Informatics 1997"

Copied!
8
0
0

加載中.... (立即查看全文)

全文

(1)

The Hong Kong Olympiad in Informatics 1997

Final Event (P.M. Session)

10 March 1997 (Monday) Time allowed: Two hours

Organisers:

Education Department, Hong Kong

The Hong Kong Association for Computer Education The Hong Kong Computer Society

(2)

1. Rectangles (20 marks)

Program Name: PROGRAM1.EXE Input File: SAMPLE1.DAT

We can use characters instead of lines to draw a rectangle. Assume that each position of the text screen of your computer can be addressed by an integer pair (c, r), where c is the column number (1 £ c £ 60) and r is the row number (1 £ r £ 20). For example, the top left corner of the screen is represented by (1, 1), the position immediately to the right of (1, 1) is represented by (2, 1), and the position at the bottom right corner is (60, 20).

Given the positions of the top left corner and the bottom right corner, a rectangle can be drawn on the screen. The following figure is an example of using the character “X” to draw a rectangle with the top left corner at (3, 2) and the bottom right corner at (7, 4).

...

..XXXXX...

..X X...

..XXXXX...

...

(Note: Only the top five lines of the screen is shown in the above example. The dots are used to show the relative positions of the screen.)

Suppose all rectangles drawn are not transparent. When more than one rectangle is drawn, part or all of the previously drawn rectangles may be covered by the rectangles that are drawn later.

You are asked to write a program to draw a number of rectangles using a number of characters. Your program should accept a filename from the keyboard, and read the given data from this file. Your program should be able to display all rectangles in the sequence as indicated in the data file.

Input Data

In the input text file SAMPLE1.DAT, there are N+1 lines, where 1 £ N £ 10. The first line of the file contains an integer N. Each of the following N lines contains a character and four integers a, b, c and d, each separated by a space. The character is any printable character and is used for drawing the sides of the rectangle. The first two integers a and b represent the position of the top left corner of the rectangle is at (a,b). The last two integers c and d represent the position of the bottom right corner of the rectangle is at (c,d).

Example Input and Output SAMPLE1.DAT

4

X 23 3 41 11 Y 18 6 28 11

* 37 2 52 7 8 14 5 31 13

HKOI'97 Final Event (P.M. Session) Page 1 of 6

(3)

Below is a sample output of the program. In these outputs, all the information following the question mark is entered through the keyboard by the user. All other items are output from the program.

Data file? SAMPLE1.DAT

****************

XXXXXXXXXXXXXX* * X * * 888888888888888888 * * 8 8 * * 8 8 ****************

8 8 X 8 8 X 8 8 X 8 8XXXXXXXXXX 8 8 888888888888888888

(4)

2. Software Competition (20 marks)

Program name: PROGRAM2.EXE Input File: SAMPLE2.DAT

In a software competition, all participants have to attempt five papers, namely, Paper 1, Paper 2, Paper 3, Paper 4 and Paper 5. The overall ranking of a participant is determined by the total score of the five papers. The passing mark of each paper is 40. If a participant fails in two or more papers, he/she will no longer be ranked. If two or more participants have the same total scores, their performance in Paper 5 will determine their rankings.

You are asked to write a program to read the scores of all participants and rank them as described above. Your program should accept a filename from the keyboard, and read the input data from this file. Your output should have the same format as shown in the sample output.

Input File

In the input text file SAMPLE2.DAT, there are N+1 lines, where 1 £ N £ 200. The first line contains a number N. Each of the following N lines contains exactly 30 characters. The first 15 characters represent the participant’s name in capital letters. The remaining 15 characters represent the scores of the participant in the five papers (in the order of Paper 1, Paper 2, ..., Paper 5). Each score occupies three places. If a score is less than three digits, it will be packed with leading spaces.

Example Input and Output SAMPLE2.DAT

4

CHAN A B 20 86 79 30 80 MA X Y 53 52 50 49 60 WONG C D 8100 70 60 40 HO S T 47 64 83 70 0

Below is a sample output of the program. In these outputs, all the information following the question mark is entered through the keyboard by the user. All other items are output from the program.

Data file? SAMPLE2.DAT STUDENT SCORE --- WONG C D 278 MA X Y 264 HO S T 264

HKOI'97 Final Event (P.M. Session) Page 3 of 6

(5)

3. Division (40 Marks)

Program Name: PROGRAM3.EXE Input File: SAMPLE3.DAT

Given two non-negative integers A and B, you are asked to write a program to calculate the exact value of A divided by B. Your program should accept a filename from the keyboard, and read the input data (A and B) from this file. Output the result to the screen in the format as shown in the sample output. Recurring decimal(s), if any, is/are put inside a pair of square brackets.

Input Data

In the input text file SAMPLE3.DAT, there are two lines of text. The first line contains an integer A and the second line contains an integer B where 0 £ A £ B, and 0 < B < 40.

Example Input and Output

SAMPLE3.DAT 8

13

Below is a sample output of the program. In these outputs, all the information following the question mark is entered through the keyboard by the user. All other items are output from the program.

Data file? SAMPLE3.DAT 8 / 13 = 0.[615384]

(6)

4. Word Chain (60 Marks)

Program Name: PROGRAM4.EXE Input File: SAMPLE4.DAT

A “word chain” is a sequence of words of the same length and any adjacent pair of words differed by exactly one letter. The following sequence of words is an example of a word chain.

MOM, MOP, MAP, TAP, TIP, SIP

You are asked to write a program to find a word chain beginning with the first word in a given set of words. On the screen, output each word of the word chain on one line as shown in the sample output below. Use the character “!” to link up the two distinct characters in the word chain as shown in the sample output. If there are more than one way of forming a word chain, you only need to display one of them. If one or more of the given words are not used, the word chain is said to be broken. In this case, print out those words which can form a word chain and also the message “This chain is broken.” Your program should accept a filename from the keyboard, and read the input data from this file.

Input Data

In the input text file SAMPLE4.DAT, there are N+1 lines. The first line of the input file contains an integer N, where 2 £ N £ 20, which represents the number of words given. Each of the following N lines contains a word in capital letters. All words are of the same length.

Example Input and Output SAMPLE4.DAT

5 TWO PAT TOP TOO POP

Below is a sample output of the program. In these outputs, all the information following the question mark is entered through the keyboard by the user. All other items are output from the program.

Data file? SAMPLE4.DAT TWO

! TOO ! TOP

! POP

This chain is broken.

HKOI'97 Final Event (P.M. Session) Page 5 of 6

(7)

5. Shortest Route (60 Marks)

Program Name: PROGRAM5.EXE Input File: SAMPLE5.DAT

A traveller wants to find the shortest distance for him to travel from one city to another city in a country. He has collected all information of bus routes travelling across different cities in the country. The name of a city in the country is represented by one alphabet in capital letter. There is no city called Z. A bus route is represented by a pair of alphabets and its order is insignificant. For example, both “AB” and “BA” represent a bus route running between city A and city B. This bus runs from A to B and also from B to A on the same route.

You are given all the bus routes in the country and the distance travelled by the bus of each route. You are asked to write a program to find the shortest route for the traveller to go from one city (starting city) to another city (ending city). Your program should accept a filename from the keyboard, and read the given data from this file. Display your result in the format as shown in the sample output below. If it is impossible to take any bus routes from the starting city to the ending city, display “Impossible.” on the screen.

Input Data

In the input text file SAMPLE5.DAT, there are at least three lines of text. Each line of text represents one line of bus route data. Each line of bus route data contains the name of a bus route and its distance D, separated by a space, where D is any positive integer less than 1000. When a text line begins with “ZZ”, it means that it is the end of the bus route data.

The next line, which is the last line in the file, contains two alphabets in capital letters. The first one is the name of the starting city, and the second one is the name of the ending city.

Example Input and Output)

SAMPLE5.DAT BC 20

AB 20 XY 30 AC 50 XC 10 ZZ AX

Below is a sample output of the program. In these outputs, all the information following the question mark is entered through the keyboard by the user. All other items are output from the program.

Data file? SAMPLE5.DAT The route is : ABCX Its length is 50

參考文獻

相關文件

You are given the wavelength and total energy of a light pulse and asked to find the number of photons it

6 City University of Hong Kong Bachelor of Arts with Honours in Primary Education Chinese major 3 years 7 City University of Hong Kong Bachelor of Arts with Honours in Language

6 City University of Hong Kong Bachelor of Arts with Honours in Primary Education Chinese major 三年 7 City University of Hong Kong Bachelor of Arts with Honours in Language

Now, nearly all of the current flows through wire S since it has a much lower resistance than the light bulb. The light bulb does not glow because the current flowing through it

You are a property agent working for the Quality Property Company. A potential client has contacted you from Australia because he will soon be moving to Hong Kong with

John studies hard and in 1911 he left the city of Melbourne and went to work in South Australia for the Presbyterian Church.. The church wanted to help the sheep farmer s who

This kind of algorithm has also been a powerful tool for solving many other optimization problems, including symmetric cone complementarity problems [15, 16, 20–22], symmetric

• Hong Kong Education City originated from a Quality Education Fund project in 2000 and developed into wholly-owned limited incorporated company of the Government of the HKSAR