| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
错了几次,居然忘了将a可以为0考虑进去#include <iostream>
using namespace std;
int* b;
int maxlist(int n)
{
const int N = n;
int k = 0,i = 0,j = 0,a;
b = new int[N + 1];
b[0] = -1;
for(i = 0;i < N;i++)
{
cin >> a;
if(a > b[k])
b[++k] = a;
else if(a < b[k])
{
for(j = k - 1;a <= b[j];j--);
b[j + 1] = a;
}
}
delete[] b;
return k;
}
int main()
{
int n;
while(cin >> n)
cout << maxlist(n) << endl;
return 0;
}
一开始我将b【0】初始化为0,结果将a=0的情况没算进去,改为-1后,终于AC了
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator