New Ket web-made Huawei 2016 machine Test topic, novice, code more chaotic, discussed together.
The subject requirements are as follows:
The teacher wants to know from the so-and-so classmate, the highest score is how many, now asks you to program the simulation teacher's inquiry. Of course, teachers sometimes need to update a student's grades.
Input Description:
The input includes multiple sets of test data. The first line of each set of inputs is two positive integers N and m (0 < N <= 30000,0 < M < 5000), representing the number of students and the number of operations respectively. Student ID number from 1 to N. The second line contains n integers, representing the initial scores of the N students, where the number of I represents the student ID is the result of the next m line, each line has a character C (only ' Q ' or ' U '), and two positive integers, a, B, when C is ' Q ', indicating that this is an inquiry operation, He asked about the number of students whose IDs were from A to B (including A, a), and the highest scores were when C was ' U ', indicating that it was an update operation that required the students with ID A to change their grades to B.
Output Description:
For each query operation, output the highest score in one line.
Input Example:
5 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 4 5U 2 9Q 1 5
Import java.util.scanner;/** * @author liangming input includes multiple sets of test data. The first line of each set of inputs is two positive integers N and m (0 < N <= 30000,0 < M < * 5000), representing the number of students and the number of operations respectively. Student ID number from 1 to N. * The second line contains n integers, representing the initial scores of the N students, where the number of I represents the student's score of ID I * Next m line, each line has a character C (just take ' Q ' or ' U '), and two positive integers a, B, when C is ' Q ', * table This is a query operation, he asked the ID from a to B (including A, a) students, the highest score of * when C is ' U ', indicates that this is an update operation, requires the ID of a student's score changed to B. */public class Highscore {public static void main (string[] args) {Scanner in = new Scanner (system.in), while (In.hasnext ()) {int n = in.nextint ();//input student number int m = In.nextint ();//input operation number int[] Stu = new int[n];//Create student array//give student number for (int i = 0; I < n; i++) {Stu[i] = In.nextint ();} int Q1, q2;//represents the start and end of the operation string c = null;for (int i = 0; i< m; i++) {c = In.next (); q1 = In.nextint (); q2 = In.nextint (); Method (c, Q1, Q2, Stu);}} In.close ();} Implement two operations private static void method (String c, int A, int b, int[] stu) {int begin,end; if (C.equals ("Q")) {end = Math.max (A, b); Begin = Math.min (A, b) -1;int max = Stu[begin];for (iNT i = begin; I < end; i++) {if (Stu[i] > max) {max = Stu[i];}} SYSTEM.OUT.PRINTLN (max);} if (C.equals ("U")) {Stu[a-1] = b;}}}
Huawei 2016 machine Test Topic 01