您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩....

老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩....

来源:化拓教育网

// ConsoleApplication12.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
// ConsoleApplication12.cpp : 定义控制台应用程序的入口点。
//

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

int main()
{
    int N;//学生数量
    int M;//测试数据
    
    while(cin >> N >> M){
        vector<char> vecOp;//操作
        vector<int> numA;
        vector<int> numB;//输入的数据
        vector<int> scores;
    for (int i = 0;i < N;++i)
    {
        int num;
        cin >> num;
        scores.push_back(num);
    }
    while (M != 0)
    {
        char op;
        int a, b;
        cin >> op >> a >> b;
        vecOp.push_back(op);
        if (op == 'Q')
        {
            numA.push_back(a - 1);
            numB.push_back(b - 1);
        }
        else {
            numA.push_back(a - 1);
            numB.push_back(b);
        }

        --M;
    }
    for (int i = 0;i < vecOp.size();++i)
    {
        if (vecOp[i] == 'Q')
        {
            int a = numA[i];
            int b = numB[i];
            if (a > b)
            {
                int temp = a;
                a = b;
                b = temp;
            }

            int max = scores[a];
            for (int j = a;j <= b;++j)
            {
                if (max < scores[j])
                {
                    max = scores[j];
                }
            }
            cout << max << endl;
        }
        else {

            scores[numA[i]] = numB[i];
        }
    }
    
    }
//  cout << endl;


    return 0;
};

转载于:https://www.cnblogs.com/wdan2016/p/17157.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务