CS102A程序 写作、 辅导Java程序设计

” CS102A程序 写作、 辅导Java程序设计CS102A Fall 2020 Assignment 2Problem 1. Hard Math Problem[Easy]DescriptionAhsoka must pass a very hard trial to become a Padawan (学徒). Now she gets stuck in a very hardmath problem: compute the integral of a Polynomial. However she has never learnt to evaluatean integral, but she knows that she can get an approximation of an integral by calculating a finitesum. Now she seeks your help.The integral is written as the form . is a polynomial and you can compute theapproximation by evaluating the value, where .InputThe Program receives input from System.in .The input Consists of 3 lines.The first line has 2 integers indicating the lower and upper bounds.The second line has only 1 non-negative number , indicating the degree of the polynomial (whichmeans the polynomial is ).The third line consists of floating point numbers, indicating the coefficients of thepolynomial.It is guaranteed that the and all the coefficients satisfywith at most 3 digits.OutputOnly one number, the approxiation of the integral using the given method. You should roundthe answer to the nearest tenth.Use double for more precise calculation.Try System.out.printf(%.1f\n, ans); for auto-rounding.Problem 2. Shattered [Hard]DescriptionAhsoka is on the run. Order 66 has been executed, and now the clone troopers are hunting downAhsoka at all costs. Ahsoka must leave the Jedi cruiser as soon as possible. The map of the Jedicruiser is given by an matrix , and (the element at the -th row, -th column of ) canbe represented by one of the following notations:1. W – Wall2. C – CorridorInitially Ahsoka lies in the Coordinate of the matrix, and she can travel through the corridorto get to the exit located at the point .Please help her escape.InputThe first line consists of 2 positive integer .For the following lines, each line contains marks ( W or C ).It is guaranteed that and points are always character C . It is alsoguaranteed that there is either no way out or only one path. There may exist some branch roadswhich lead to dead ends, but the branches have maximum length of 1 and there are no otherbranches on a branch.OutputThe first line contains one word Yes or No (without quotes) indicates whether Ahsoka cansuccessfully escape or not.If the answer is Yes (without quotes), then print the coordinate of each step Ahsoka has to takein order. One Coordinate per line.1 354.3Sample Input 1Sample Output 1Sample Input 2Sample Output 2HintTry using charAt() to fetch character(s) from a String .Problem 3. Harmonic Strings [Medium]DescriptionA noob guitarist is trying hard to study Java. One day he comes up with a strange idea: Since thecharacter sequence is called String in Java, can it produce harmonic sounds like a guitar do?He wants to verify his thoughts as soon as possible, but he still has tons of bugs to fix. Fortunately,you are so kind to help him to do the calculation.For a string , let be the length of the string, then the frequency produced by the string is:Where represents the modulus operation, and represent the ASCII code for thecharacters in respectively.You are given strings and you need to calculate the frequency for each string. To simplify theproblem, you Only need to return the ratio of the largest and smallest one in rational numberform , where and are relatively prime (互素), i.e. .InputThe program receives input from System.in .The first line contains an integer , where .For the following lines, each line contain a string with length not exceeding .OutputTwo integers and (which are described above), separated by a space.Sample InputSample OutputExplanationThe frequencies of the two strings are and respectively, and .Watch out for integer overflowing!Problem 4. Silly Calculator [Medium]DescriptionMacromogic is not getting along well with his roommate recently. He decides to hack into hisroommates CASIO fx-991CN calculator to mess him up in the exam. The project may be huge, sohe hires you to do the simple steps.You are given a sequence containing digits and arithmetic operators ( + , – , * , / ). The only thingyou should do is to calculate the result from left to right, regardless of the operatorprecedence. It is guaranteed that the numbers in the sequence are in the range of int type, andyou do not need to care if there is an overflow. The divisor will never be 0, and if the divisionresult is not an integer, just take the integral part (i.e. the maximum integer not exceeding thenumber). For Example:If you can finish his task successfully, you will not get paid or receive other rewards, but you canget full marks in this assignment.InputThe program receives input from System.in .The input has only one line, containing a string as described above. It is guaranteed that the stringstarts with a digit.OutputOne integer, Representing the calculation result.Sample InputSample OutputExplanationProblem 5. Jimmys Lottery [Medium]Description1 1+2*6/5-91 -6Jimmy is a boy who is interested in lottery recently. He wants to define a new kind of lottery byhimself. The new kind of lottery is a set of number which is similar as the original lottery, butJimmy has changed the rule. For all sets of number in every turn, there is a standard set which willbe used to calculate the other sets scores. For each digit in a set, if it is the same as the digit in thestandard set at the same position, one gets 2 points for this digit. If the absolute differencebetween two number is less than 3, one gets 1 point. Otherwise one gets no points. For example,if the standard set is and your set is , then your score will bepoints.To make it more fun, Jimmy also set a lucky number. The lucky number can only be calculated byall digits in set. The formula for the lucky number is (for given lucky divisor ,and represents each digit in the set). The lucky number is also counted for final score, whichhas the same rule as other digits (mentioned above). For example, the standard set is andyour set is with given , then the standard lucky number is ,and your sets lucky number is . Their difference is 2, so for lucky numberyou will get 1 point according to the rule. The final score for your set will be .Youre a well-known programmer, so Jimmy wants you to write a program for him to calculateeach sets score quickly.InputThe program receives input from System.in .The input contains several lines. The first line is the number of test cases , the length for setand the lucky divisor . The next line shows the standard set. The following lines will show alltest cases, one in a line.Its guaranteed that , , . The range for numbers in set is. All numbers Are integers.OutputOutput the score for each set. One score in a line.Sample Input 2Sample Output 2Problem 6. Easy Multiplication Plus[Bonus]Matrix multiplication, easy peasy. Right?How about try something more challenging? Given matrices , can you calculate?If you do not know how to multiply matrices, please refer to your Linear Algebra textbook (or thedescription in Easy Multiplication).InputThe program receives input from System.in .The first line contains two integer , denoting the number of matrices and the exponent index.Then the following lines describes the matrices in order.For the -th matrix , The first line contains two positive integers denoting that the matrixis . Then for the next lines, each line contains integers, which represent theentries of the matrix.It is guaranteed that for all and .Note that the input data may be huge, please:1. Use the provided Reader class for input, otherwise your program will be very slow!import java.io.*;import java.util.StringTokenizer;class Main {public static void main(String[] args) {Reader reader = new Reader(System.in);// Write your code below.// You may use `reader.nextInt() to read integers.3. Use Quick power algorithm to calculate the matrix power:}// You do not necessarily understand the code below currently.private static class Reader {BufferedReader in;StringTokenizer tokenizer;public Reader(InputStream inputStream) {in = new BufferedReader(new InputStreamReader(inputStream));}private String next() {while (tokenizer == null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(in.readLine());} catch (IOException e) {e.printStackTrace();}}return tokenizer.nextToken();}public int NextInt() {return Integer.parseInt(next());}}}The following is the pseudocode for `Quick Power (Assume we are tocalculate a^b mod m):ans = 1for all binary digits d of b (from right to left):An square matrix, representing the total product. Entries in the same row are separatedby a space.如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导