64,282
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
using namespace std;
void foo(const vector<int>& arr)
{
vector<int> re;
for (size_t i = 0; i < arr.size(); ++i)
{
vector<int> te;
te.push_back(arr[i]);
for (size_t j = i + 1; j < arr.size(); ++j)
{
if (arr[j] > arr[j - 1])
{
te.push_back(arr[j]);
}
else
{
break;
}
}
if (te.size() > re.size())
{
re = te;
}
}
for (size_t i = 0; i < re.size(); ++i)
{
cout << re[i] << ' ';
}
cout << endl;
}
int main()
{
int a[] = {5, 1, 2, 3, 0, 8, 9};
vector<int> arr(a, a + sizeof(a) / sizeof(*a));
foo(arr);
return 0;
}
#include "iostream.h"
int steplong(int array[],int head,int n)
{
if(n==2)
{
if (array[head]+1==array[head+1])
{
return 2;
}
else
{
return 1;
}
}
else
{
if(array[n-2]+1==array[n-1])
{
return (steplong(array,head,n-1))+1;
}
return (steplong(array,head,n-1));
}
}
main()
{
int num[]= {1,2,3,0,1};
cout<<steplong(num,0,5)<<endl;
return 0;
}