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


// 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;
};


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM