華爲2016校園招聘上機筆試題-最高分是多少

#include<bits/stdc++.h>
using namespace std;
int FindMax(vector<int>& vec,int A,int B)
{
    int MaxValue=vec[A-1];
    for(int i=A;i<B;i++)
    {
        if(vec[i]>MaxValue)
        {
            MaxValue=vec[i];
        }
    }
    return MaxValue;
}
int main()
{
    ios::sync_with_stdio(false);
    int N,M;
    int tmp;
    int MaxValue;
    int A,B;
    char op;
    vector<int> vec;
    while(cin>>N>>M)
    {
        vec.clear();

        for(int i=0;i<N;i++)
        {
            cin>>tmp;
            vec.push_back(tmp);
        }
        while(M--)
        {
            cin>>op;
            //cout<<op<<endl;
            cin>>A>>B;
           
            if(op=='Q')
            {
                 if(B<A)
            {
                swap(A,B);
            }
                MaxValue=FindMax(vec,A,B);
                cout<<MaxValue<<endl;
            }
            else
            {
                vec[A-1]=B;
               // cout<<A<<":"<<B<<endl;
            }
        }
    }

    return 0;
}

 

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