Title Description:
The teacher wants to know how many points the highest score from XXX to XXX students.
Now please program the mock Teacher's inquiry. Of course, teachers sometimes need to update a student's grades.
Topic Category: sort
Difficulty: Beginner
Run time limit: Unlimited
Memory limit: Unlimited
Stage: pre-employment practice
Input:
The input contains 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), and the table represents the number of students and the number of operations.
Student ID number from 1 to N.
The second line contains n integers representing the initial scores of the N students, of which the number of I represents the student's score for ID i.
Then there's M-line. Each line has a character C (only ' Q ' or ' U '), and two positive integers, A/b.
When C is ' Q ', it indicates that this is a query operation, which asks for the highest number of students whose IDs are from a to B (including A, a).
When C is ' U ', it indicates that this is an update operation that requires the student with ID A to change the grade to B.
Output:
For each query operation, output the highest score in one line.
Sample input:
5 6
1 2 3) 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
Sample output:
5
6
5
9
The code is as follows:
public class Zui_gaofen{public static void Main (string[] args) {Scanner sc=new Scanner (system.in);//Initialization Data N: Number of students M: number of Operations St Ring Firstline=sc.nextline (); String[] Initalnums=firstline.split (""); int n=integer.parseint (initalnums[0]); int M=integer.parseint (initalNums[1 ]);//initialization score string secondline=sc.nextline (); int []scores=new int[n];scores=getscores (Secondline);//Command int[] Max=new Int[m];int count=0;for (int i = 0; i < M; i++) {String q_or_u=sc.next (); if (Q_or_u.equals ("Q")) {int a=sc.nextint (); int b =sc.nextint (); Max[count]=getmax (scores,a-1,b-1); count++;} if (Q_or_u.equals ("U")) {int a=sc.nextint (); int b=sc.nextint (); scores[a-1]=b;}} for (int i = 0; i < count; i++) {System.out.println (max[i]);} Sc.close ();} public static int Getmax (int[] Score,int a,int b) {int temp=score[a];for (int i = A; I <= b; i++) {if (score[i]>temp) { Temp=score[i];}} return temp;} public static int[] Getscores (String secondline) {string[] Scores=secondline.split (""); int []res=new int[scores.length ];for (int i = 0; I &lT Scores.length; i++) {res[i]=integer.parseint (scores[i]);} return res;}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2015 Huawei Machine Test--what is the highest score?