不是VIP会员,不能显示答案

题目解答

题目:
#include <iostream>
using namespace std;
int n,m;
int a[100],b[100];
bool tmp;
int main()
{
cin>>n>>m;
for (int i=1; i<=n; i++)
cin>>a[i];
for (int i=1; i<=m; i++)
cin>>b[i];
for (int i=1; i<=n-m+1; i++)
{
tmp=true;
for (int j=1; j<=m; j++)
if (a[i+j-1]!=b[j])
tmp=false;
if (tmp) cout<<i<<endl;
}
return 0;
}
输入:
8 2
10 15 2 3 4 7 3 12 3 4
运行结果为:
输出:4
考点: 0
分析:
解答: 在数列中找子序列的位置,即10 15 2 3 4 7 3 12中找子序列3 4的起始位置
评论:
老师: 0