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


    // 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;
    };
  • 相关阅读:
    Redis 安装
    Git的安装和使用
    HTML5 本地存储+layer弹层组件制作记事本
    PHP 微信公众号开发
    PHP 微信公众号开发
    Electron 安装与使用
    HTML5 桌面消息提醒
    Composer安装和使用
    玄 学
    区间内的真素数
  • 原文地址:https://www.cnblogs.com/wdan2016/p/6417157.html
Copyright © 2020-2023  润新知