题目: |
#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
|