题解 AT2820 【最大値】
小可爱三岁七
2018-03-08 21:30:37
额。。。入门水题(最近刷上瘾了233....)
思路是这样的:维护一个$maxx$表示当前最大的是多少,然后比较输入的数和现在的$maxx$比较,取较大的值作为$maxx$.
代码如下:
```cpp
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;//头文件不解释
int n;
int now;//打酱油的的变量
int maxx;
int main()
{
scanf("%d",&n);//n个数
for(int i=1;i<=n;i++)//循环输入
scanf("%d",&now),
maxx=max(maxx,now);//在线更新
printf("%d",maxx);
return 0;//程序拜拜。
}
```