華爲[編程題]最高分是多少-牛客網

#include<iostream>
#include<vector>
using namespace std;

int main(){
    int n,m;
    while(cin>>n>>m){
        vector<int>stu(n);
    for(int i=0;i<n;i++){
        cin>>stu[i];
    }//輸入初始成績;
    
         char c;int a;int b;
        for(int j=0;j<m;j++){
            cin>>c>>a>>b;
            if(c=='Q'){
                if(a>b)swap(a,b);
            //調整q時的左右邊界值,確保在合理範圍內;
                int max=stu[a-1];//將範圍內的第一個值作爲初始max;
                for(int k=a;k<b;k++){
                if(max<stu[k]) {max=stu[k];}
                }
                cout<<max<<endl;//遍歷範圍[a,b]中的值,找出最大值;
            }
            if(c=='U'){stu[a-1]=b;}//覆蓋
        }//操作數,即輸出數;
    }
   return 0;
    
}

總結:其實本題目挺簡單的,但是之前一直在LeetCode上解題,模式不太一樣,牛客網什麼都不給,讓自己輸入輸出,所以會比較糾結對題目的理解這一塊;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章