【发布时间】:2017-12-02 23:37:02
【问题描述】:
在解决 this question 时,我的代码似乎不适用于 100000 等较大的输入,但似乎适用于较小的输入。
代码如下:
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
long long int n, h;
cin>>n;
long long int count=0;
long long int i,j;
long long int arr[n];
for(i=0;i<n;i++)
{
cin>>arr[i];
//cout<<arr[i]<<" ";
}
h = arr[0];
for(i=0;i<n;i++)
{
if (arr[i]>=h)
{
h=arr[i];
for(j=i;j<n;j++)
{ if (arr[j]<h)
count++;
}
}
}
cout<<(n-count);
//cout<<h;
return 0;
}
谁能帮帮我?
【问题讨论】:
-
这实际上不是 C++,因为您忽略了可以避免这些问题的出色标准库容器,而是使用 VLA 的非标准扩展。
-
明白了,抱歉我是初学者,所以没有太多经验。感谢您的帮助。