题目描述
炎热的夏日,KC 非常的不爽。他宁可忍受北极的寒冷,也不愿忍受厦门的夏天。最近,他开始研究天气的变化。他希望用研究的结果预测未来的天气。
经历千辛万苦,他收集了连续 N(1 \leq N \leq 10^6)N(1≤N≤106) 的最高气温数据。
现在,他想知道最高气温一直上升的最长连续天数。
输入格式
第 1 行:一个整数 NN 。1 \leq N \leq 10^61≤N≤106
第 2 行:NN个空格隔开的整数,表示连续 NN 天的最高气温。0 \leq0≤ 最高气温 \leq 10^9≤109 。
输出格式
1 行:一个整数,表示最高气温一直上升的最长连续天数。
输入输出样例
输入 #1
10 1 2 3 2 4 5 6 8 5 9
输出 #1
5
###第一次没看数据范围直接搞RE了
#include <iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
int n;
int a[N], s[N];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
int res = 1;
int cnt = 0;
for(int i = 0;i < n;i++){
if(a[i + 1] > a[i]){
cnt++;
}else {
cnt = 0;
}
res = max(res,cnt);
}
cout << res+1;
return 0;
}
###第二次因为没判断0对了7个测试点
#include <iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
int n;
int a[N], s[N];
int main()
{
scanf("%d", &n);
int x = 0;
int a[2];
int res = 0;
while(n --){
cin >> a[1];
if(a[1] > a[0]){
x++;
res=max(x,res);
}else x = 0;
a[0] = a[1];
}
cout << res+1;
return 0;
}
###过的代码
#include <iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
int n;
int a[N], s[N];
int main()
{
scanf("%d", &n);
int x = 0;
int a[2];
int res = 0;
while(n --){
cin >> a[1];
if(a[1] > a[0]){
x++;
res=max(x,res);
}else x = 0;
a[0] = a[1];
}
if(res == 0){
cout << 0;
}else cout << res+1;
return 0;
}
浙公网安备 33010602011771号