CUHKSZ CSC2003 24Spring Assignment 3
Important Notes
CSC2003 Assignment 3
CSC2003 Teaching Group March 31, 2024
-
The assignment is an individual project, to be finished on one’s own effort.
-
The work must be submitted before 6 p.m., Apr. 21st, 2024 (Sunday), Beijing Time. 20% mark deduction will be given for late submission within 2 days, and 0 for even later;
-
Plagiarism is strictly forbidden, regardless of the role in the process. Notably, ten consecutive lines of identical codes are treated as plagiarism. Using AI to directly generate code will also be regarded as plagiarism. Depending on the seriousness of the plagiarism, 30% − 100% marks will be deducted.
Marking Criterion
-
The full score of the assignment is 300 marks.
-
Three java programs are to be submitted. Each program will be evaluated with several unseen test cases. A submission obtains the full score if and only if both programs pass all test cases.
Running Environment
-
The submissions will be evaluated in the OJ system running Java SDK 21. It is the students’ responsibility to make sure that his/her submissions are compatible with the OJ system.
-
The submission is only allowed to import four packages of (java.lang.*; java.util.*; java.math.*; java.io.*) included in Java SDK, and StdIn / StdOut from textbook. No other packages are allowed.
-
All students will have an opportunity to test their programs in the OJ platform prior to the official submission.
Submission Guidelines
-
You will get your grade only if you submit your code both on OJ and on bb on time.
-
For bb submission, you need to directly upload your java file on bb. That is, your sub- mission should be BanishLetter.java, WordSearching.java, and MathExpr2.java. Wrong submission format will receive 10% mark deduction.
-
Inconsistency with or violation from the guideline leads to marks deduction.
-
All students are reminded to read this assignment document carefully and in detail. No argu- ment will be accepted on issues that have been specified in this document.
1
CUHKSZ CSC2003 24Spring Assignment 3
Programs
There are 3 independent programs in this assignment, and each is worth 100 points.
Banish Letter
Given multiple char values and strings, write a Java program named ”BanishLetter.java” that delete all the given char values from the strings.
Input: The first line contains multiple char values C = {c1,c2,...,cn}, each seperated by a space. The second line is a positive integer T, followed by T lines of strings.
Output: For each string s, delete all characters c ∈ s such that c ∈ C, and output the result. That is, the output should be T lines. There’s no extra space at the end of a line, or extra blank row between two lines.
Foralltestcases,1≤T≤100,1≤lengthofs≤30,1≤n≤30. Allci ∈Candcharacters in strings are upper case letters, or lower case letters, or digits.
An example of console input Expected console output
An example of console input Expected console output
WordSearching
Given an m × n 2D character grid board and multiple string words. For each word ∈ words, print true if word exists in the grid, and print false otherwise.
A word must be formed from letters in adjacent cells in right order, where ”adjacent” cells are those that are adjacent horizontally or vertically. Letters in the same cell are not allowed to be used repeatedly.
Hint: You can refer to the following example for better understanding.
Input: The first line contains 2 integers m,n, each separated by a space. Then, for the follow- ing m lines, each line contains n capital letters separated by a space. Then, the following line is a integer T ; for the following T lines, each line contains a string consisting of only capital letters.
Output: For each string, output true if the string exists in the grid, and output false otherwise. Foralltestcases,1≤m,n≤30,1≤T ≤10,and1≤thelengthofeachstring≤30.
olk |
HeWrd |
C0S |
23 cuhksz witch |
2
CUHKSZ
An example of console input
CSC2003 24Spring Expected console output
Assignment 3
34
IAXR
SIRI
RITS
1 |
true |
An example of console input
Expected console output
34 CBCB ADBA DBCB 3 ABCBA CBCBA DBCBDB |
false true true |
Math Expression 2
Write a Java Program (MathExpr2.java) with the following requirement.
(1) It evaluates the value of math expressions, and outputs an integer value.
-
(2) Each math expression includes (see the example below): numbers (integers and doubles); op- erators of “+” (addition), “-“ (subtraction), “*” (multiplication) and “/” (division); functions including “sin” (sine function), “cos” (cosine function), “tan” (tangent function) and “sqrt” (square root function); “(“ and “)” (brackets); possibly blank space.
-
(3) All expressions are valid. The output is an integer value after rounding. 3
CUHKSZ CSC2003 24Spring Assignment 3
Input: The first line is a integer T . For the following T lines, each contains a math expression.
Output: T lines, each containing a integer, which is the result of the corresponding expression.
For all test cases, 1 ≤ T ≤ 30, and 1 ≤ length of a expression ≤ 50.
An example of console input Expected console output
8 |
-1 22 -2 4 -30 -31 67 0 |
4