程序代写代做代考 Java ada compiler 2016

2016

Canadian

Computing

Competition:

Junior

Division

Sponsor:

1

Canadian Computing Competition

Student Instructions for the Junior Problems

1. You may only compete in one competition. If you wish to write the Senior paper, see the
other problem set.

2. Be sure to indicate on your Student Information Form that you are competing in the Junior
competition.

3. You have three (3) hours to complete this competition.

• if your supervising teacher is grading your solutions, all input is from the keyboard;
• if you are using the On-line CCC grader, all input is from standard input;
• all output is to standard output (i.e., to the screen).

There is no need for prompting. Be sure your output matches the expected output in terms
of order, spacing, etc. IT MUST MATCH EXACTLY!

4. Do your own work. Cheating will be dealt with harshly.

5. Do not use any features that the judge (your teacher or the On-line Grader) will not be able
to use while evaluating your programs. In particular, take note of the type and version of the
compiler used for your programming language on the On-line Grader if you are using the
On-line Grader.

6. Books and written materials are allowed. Any machine-readable materials (like other pro-
grams which you have written) are not allowed. However, you are allowed to use “stan-
dard” libraries for your programming languages; for example, the STL for C++, java.util.*,
java.io.*, etc. for Java, and so on.

7. Applications other than editors, compilers, debuggers or other standard programming tools
are not allowed. Any use of other applications will lead to disqualification.

8. If your teacher is grading, please use file names that are unique to each problem: use
j1.pas or j1.c or j1.java (or some other appropriate extension) for Problem J1. If
you are using the On-line Grader, follow naming rules described there (and take particular
note of file and class names for Java programs).

9. Your program will be run against test cases other than the sample ones. Be sure you test your
program on other test cases. Inefficient solutions may lose marks for some problems. Be
sure your code is as efficient (in terms of time) as possible. You will have at most 5 seconds
of execution time per test case.

10. Check the CCC website at the end of March to see how you did on this contest and to see
who the prize winners are. The CCC website is:

www.cemc.uwaterloo.ca/ccc

2

Problem J1: Tournament Selection

Problem Description
Each player in a tournament plays six games. There are no ties. The tournament director places
the players in groups based on the results of games as follows:

• if a player wins 5 or 6 games, they are placed in Group 1;

• if a player wins 3 or 4 games, they are placed in Group 2;

• if a player wins 1 or 2 games, they are placed in Group 3;

• if a player does not win any games, they are eliminated from the tournament.

Write a program to determine which group a player is placed in.

Input Specification
The input consists of six lines, each with one of two possible letters: W (to indicate a win) or L (to
indicate a loss).

Output Specification
The output will be either 1, 2, 3 (to indicate which Group the player should be placed in) or -1
(to indicate the player has been eliminated).

Sample Input 1
W
L
W
W
L
W

Output for Sample Input 1
2

Sample Input 2
L
L
L
L
L
L

Output for Sample Input 2
-1

3

Problem J2: Magic Squares

Problem Description
Magic Squares are square arrays of numbers that have the interesting property that the numbers in
each column, and in each row, all add up to the same total.

Given a 4⇥ 4 square of numbers, determine if it is magic square.

Input Specification
The input consists of four lines, each line having 4 space-separated integers.

Output Specification
Output either magic if the input is a magic square, or not magic if the input is not a magic
square.

Sample Input 1
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

Output for Sample Input 1
magic

Explanation for Output for Sample Input 1
Notice that each row adds up to 34, and each column also adds up to 34.

Sample Input 2
5 10 1 3
10 4 2 3
1 2 8 5
3 3 5 0

Output for Sample Input 2
not magic

Explanation for Output for Sample Input 2
Notice that the top row adds up to 19, but the rightmost column adds up to 11.

4

Problem J3: Hidden Palindrome

Problem Description
A palindrome is a word which is the same when read forwards as it is when read backwards. For
example, mom and anna are two palindromes.

A word which has just one letter, such as a, is also a palindrome.

Given a word, what is the longest palindrome that is contained in the word? That is, what is the
longest palindrome that we can obtain, if we are allowed to delete characters from the beginning
and/or the end of the string?

Input Specification
The input will consist of one line, containing a sequence of at least 1 and at most 40 lowercase
letters.

Output Specification
Output the total number of letters of the longest palindrome contained in the input word.

Sample Input 1
banana

Output for Sample Input 1
5

Explanation for Output for Sample Input 1
The palindrome anana has 5 letters.

Sample Input 2
abracadabra

Output for Sample Input 2
3

Explanation for Output for Sample Input 2
The palindromes aca and ada have 3 letters, and there are no other palindromes in the input
which are longer.

Sample Input 3
abba

Output for Sample Input 3
4

5

Problem J4: Arrival Time

Problem Description
Fiona commutes to work each day. If there is no rush-hour traffic, her commute time is 2 hours.
However, there is often rush-hour traffic. Specifically, rush-hour traffic occurs from 07:00 (7am)
until 10:00 (10am) in the morning and 15:00 (3pm) until 19:00 (7pm) in the afternoon. During
rush-hour traffic, her speed is reduced by half.

She leaves either on the hour (at XX:00), 20 minutes past the hour (at XX:20), or 40 minutes past
the hour (at XX:40).

Given Fiona’s departure time, at what time does she arrive at work?

Input Specification
The input will be one line, which contains an expression of the form HH:MM, where HH is one of
the 24 starting hours (00, 01, . . ., 23) and MM is one of the three possible departure minute times
(00, 20, 40).

Output Specification
Output the time of Fiona’s arrival, in the form HH:MM.

Sample Input 1
05:00

Output for Sample Input 1
07:00

Explanation for Output for Sample Input 1
Fiona does not encounter any rush-hour traffic, and leaving at 5am, she arrives at exactly 7am.

Sample Input 2
07:00

Output for Sample Input 2
10:30

Explanation for Output for Sample Input 2
Fiona drives for 3 hours in rush-hour traffic, but only travels as far as she normally would after
driving for 1.5 hours. During the final 30 minutes (0.5 hours) she is driving in non-rush-hour
traffic.

Sample Input 3
23:20

6

Output for Sample Input 3
01:20

Explanation for Output for Sample Input 3
Fiona leaves at 11:20pm, and with non-rush-hour traffic, it takes two hours to travel, so she arrives
at 1:20am the next day.

7

Problem J5: Tandem Bicycle

Problem Description
Since time immemorial, the citizens of Dmojistan and Pegland have been at war. Now, they have
finally signed a truce. They have decided to participate in a tandem bicycle ride to celebrate the
truce. There are N citizens from each country. They must be assigned to pairs so that each pair
contains one person from Dmojistan and one person from Pegland.

Each citizen has a cycling speed. In a pair, the fastest person will always operate the tandem
bicycle while the slower person simply enjoys the ride. In other words, if the members of a pair
have speeds a and b, then the bike speed of the pair is max(a, b). The total speed is the sum of the
N individual bike speeds.

For this problem, in each test case, you will be asked to answer one of two questions:

• Question 1: what is the minimum total speed, out of all possible assignments into pairs?

• Question 2: what is the maximum total speed, out of all possible assignments into pairs?

Input Specification
The first line will contain the type of question you are to solve, which is either 1 or 2.

The second line contains N (1  N  100).

The third line contains N space-separated integers: the speeds of the citizens of Dmojistan.

The fourth line contains N space-separated integers: the speeds of the citizens of Pegland.

Each person’s speed will be an integer between 1 and 1 000 000.

For 8 of the 15 available marks, questions of type 1 will be asked. For 7 of the 15 available marks,
questions of type 2 will be asked.

Output Specification
Output the maximum or minimum total speed that answers the question asked.

Sample Input 1
1
3
5 1 4
6 2 4

Output for Sample Input 1
12

8

Explanation for Output for Sample Input 1
There is a unique optimal solution:

• Pair the citizen from Dmojistan with speed 5 and the citizen from Pegland with speed 6.
• Pair the citizen from Dmojistan with speed 1 and the citizen from Pegland with speed 2.
• Pair the citizen from Dmojistan with speed 4 and the citizen from Pegland with speed 4.

Sample Input 2
2
3
5 1 4
6 2 4

Output for Sample Input 2
15

Explanation for Output for Sample Input 2
There are multiple possible optimal solutions. Here is one optimal solution:

• Pair the citizen from Dmojistan with speed 5 and the citizen from Pegland with speed 2.
• Pair the citizen from Dmojistan with speed 1 and the citizen from Pegland with speed 6.
• Pair the citizen from Dmojistan with speed 4 and the citizen from Pegland with speed 4.

Sample Input 3
2
5
202 177 189 589 102
17 78 1 496 540

Output for Sample Input 3
2016

Explanation for Output for Sample Input 3
There are multiple possible optimal solutions. Here is one optimal solution:

• Pair the citizen from Dmojistan with speed 202 and the citizen from Pegland with speed 1.
• Pair the citizen from Dmojistan with speed 177 and the citizen from Pegland with speed 540.
• Pair the citizen from Dmojistan with speed 189 and the citizen from Pegland with speed 17.
• Pair the citizen from Dmojistan with speed 589 and the citizen from Pegland with speed 78.
• Pair the citizen from Dmojistan with speed 102 and the citizen from Pegland with speed 496.

This sum yields 202 + 540 + 189 + 589 + 496 = 2016.

9

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *