2015 machine test-what is the highest score, and 2015 machine's highest score

Source: Internet
Author: User

2015  machine test-what is the highest score, and 2015  machine's highest score

Description:

The teacher wants to know the highest score from xx to xx.
Now, ask the simulation instructor. Of course, teachers sometimes need to update their scores.
 
Question category: Sorting
Difficulty: elementary
Running time limit: Unlimited
Memory limit: Unlimited
Stage: Pre-Employment exercises
Input:
The input contains multiple groups of test data.
The first row of each group is two positive integers N and M (0 <N <= 5000, 0 <M <). The sub-table represents the number of students and the number of operations.
Student ID numbers are numbered from 1 to N.
The second row contains N integers, indicating the initial score of the N students. The number of I represents the score of the students whose ID is I.
Next there are M rows. Each line has A character C (only 'q' or 'U'), and two positive integers A and B.
When C is 'Q', it indicates that this is A query operation. It asks the students whose ID ranges from A to B (including A and B) about the highest score.
When C is 'U', it indicates that this is an update operation. You must change the score of students whose ID is A to B.


Output:
Output the highest score in one row for each query operation.
 
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) {consumer SC = new consumer (System. in); // initialization data N: Student count M: Operation count String firstLine = SC. nextLine (); String [] initalNums = firstLine. split (""); int N = Integer. parseInt (initalNums [0]); int M = Integer. parseInt (initalNums [1]); // initialize the result 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); 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 =; 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 <scores. length; I ++) {res [I] = Integer. parseInt (scores [I]);} return res ;}}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.