大神过来帮帮小弟,oj上的一道题,提交上去是Runtime Error,怎么改都不行,运行结果是正确的
这是我的代码,题目在下面,求大神帮我看下!小弟感激不尽。#include <stdio.h>
int main()
{
int t,n,j,x;
int a[50];
scanf("%d",&t);
while(t--)
{
x=0;
scanf("%d",&n);
for(j=1;j<=n;j++)
scanf("%d",&a[j]);
for(j=2;j<=n-1;j++)
{
if((a[j]>a[j-1])&&(a[j]>a[j+1]))
x++;
}
printf("%d\n",x);
}
return 0;
}
下面是题目;
As an artist, Bob usually need to travel around the world. He made a lot of sketch of scenery on his journey. A famous spot he have visited recently is the Himalayas. The Himalayas is a mountain range in South Asia separating the plains of the Indian subcontinent from the Qinghai-Tibet Plateau. The Himalayas include over a hundred mountains exceeding 7,200 meters in elevation.
作为一名艺术家,鲍勃通常需要环游世界。他在旅途中画了许多风景。他最近访问过的一个著名景点是喜马拉雅山。喜马拉雅山是南亚的一个山脉,它将印度次大陆的平原与青藏高原分隔开。喜马拉雅山的海拔超过7200米。
One day, Bob came up with an strange idea. He wanted to know the number of mountain peaks in his paintings. As his best friend, he turned to you for help. You are given a list of N height sampling values Hi. You should determine how many peaks are there. For all i which satisfies 2 ≤ i ≤ N - 1, Hi is defined as a peak if and only if Hi-1 < Hi > Hi+1.
有一天,鲍勃提出了一个奇怪的想法。他想知道他画中山峰的数量。作为他最好的朋友,他向你求助。你会得到一个N高采样值的列表。你应该确定那里有多少个山峰。对于满足2的所有i-1,Hi被定义为一个最大值如果且仅当Hi-1小于Hi+1。
Input
输入
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
有多个测试用例。第一行输入包含一个整数T,表示测试用例的数量。为每个测试用例:
The first line contains one integer N (1 ≤ N ≤ 50). The next line contains N integers Hi (1 ≤ Hi ≤ 8848). It is guaranteed that any two adjacent height sampling values will be different.
第一行包含一个整数N(1 N 50)。下一行包含N个整数(1 Hi 8848)。它保证任何两个相邻的高度采样值都是不同的。
Output
输出
For each test case, output the number of peaks.
对于每个测试用例,输出峰值的数量。
Sample Input
样例输入
2
9
九
1 3 2 4 6 3 2 3 1
1 3 2 4 6 3 2 3 1
5
五
1 2 3 4 5
1 2 3 4 5
Sample Output
样例输出
3
0
0