讲解
各位肯定都遇到过求最大最小值的题目吧
一般都是让用字典序输出
这时候怎么办呢
这里提供一个方法
打擂台
我们找出一个最大值(最小值),然后再把数组里每一个数与他比较,如果比他大(小),就更新数值,最终剩下来的就是按字典序的最大值(最小值)了
代码演示:
#include <iostream>
using namespace std;
const int N=1e6+10;
int num[N];
int main(){
int n;
cin>>n;
int maxx=-1;
for(int i=1;<