1.(What a Simple Research)(30 Points)
Doctor Li is doing some research on Chinese ancient
music. Many Chinese ancient music has only five kinds of tones, which can be denoted by
‘C’,‘D’,‘E’,‘G’, and ‘A’. Given a piece of music score, Li wants to do some simple statistics.
Input
There are no more than 20 test cases.
In each test case:
The first line contains two integers n and m (2 <= n, m<=20), indicating that a piece of music
score is represented by an n*m matrix of tones. Only ‘C’,‘D’,‘E’,‘G’, and ‘A’ can appear in the
matrix.
Then the n*m matrix follows.
The input ends with a line of ‘0 0’.
Output
For each test case:
For each kind of tone shown in the matrix, calculate the appearing times of it, and print the
result in descending order according to the appearing times. If more than one kind of tones has
the same appearing times, print them in the lexicographical order.
1 | Sample Input |
1 | import java.util.Scanner; |
2.(Reverse Words in a String)(30 Points)
Given a string, you need to write a program to
reverse the order of characters in each word within a sentence while still preserving whitespace
and initial word order.
1 | Input: "Let's take LeetCode contest" |
1 | import java.util.Scanner; |
3. (Maximum Submatrix)(40 Points)
Given an n*n matrix composed of 0 or 1, determine the
top left corner position and the order of the maximum submatrix in which all of element are 1.
1 | Input: |
1 | import java.util.*; |
4. Chess
implement a simple chess game
Project implementation:
The following is the provided code framework:
Experiment
implement all the class methods under the chessmen folder. Note that the chessman classes inherit from a abstract base class Chessman in cn/edu/sysu/jood/core/Chessman.java
For each chessman, you need to complete three functions, which are listed as follows:
1 | /* |
canGo: Can chessman move? For example, the queen at 1d(row 1, column d)wants to move to 4f, as 4f is not on the diagonal对角线 direction, thus canGo should return false.
Path: A list of points that is he path from current position to the target position. For example, the queen at 1d wants to move to 5h, thus the Path function should return 2e 3f 4g.
status: Return the status of the chessmen (e.g, King, Queen, Knight…..)
Caution:
Only the simple rules are required, the rules related to chessboard are for later experiment. For example, a rook can move any number of squares along a rank or file but cannot leap over other pieces, in which “move any number of squares along a rank or file “ is simple rule, and”cannot leap over other pieces” is chessboard rule.
Rules:
- King: The king moves one square in any direction.
- Queen: The queen moves any number of squares in any direction.
- Rook: A rook can move any number of squares along a rank or file.
- Bishop: A bishop can move any number of squares diagonally.
- Knight: A knight moves to any of the closest squares that are not on the sane rank, file, or diagonal.(Thus the move forms an “L”-shape: two squares vertically and one square horizontally, or two squares horizontally and one square vertically.)
- Pawn: A pawn can move forward to the unoccupied square immediately in front of it on the sanme file.
Judgement
We will use the Junit framework to test each class of chessmen.
1 | //Bishop.java |
1 | //King.java |
1 | //Knight.java |
1 | //Pawn.java |
1 | //Queen.java |
1 | //Rook.java |