当前位置:网站首页>1147: find subarray
1147: find subarray
2022-04-21 09:10:00 【Qian Qian】
1147: Find subarray
Title Description
Given two arrays of integers , Array a Yes n Elements , Array b Yes m Elements ,1<=m<=n<100, Please check the array b Is it an array a Subarray . If from array a Some element of a[i] Start , Yes b[0]=a[i],b[1]=a[i+1],…,b[m]=a[i+m], It's called an array b It's an array a Subarray .
Input
Enter two integers in the first line n and m; Second row array a Of n It's an integer ; The third line is array b Of m It's an integer , The data are separated by spaces .
Output
Output takes up one line . if b yes a Subarray , Then the position of the output subarray i, Pay attention to subscripts from 0 Start ; Otherwise output “No Answer”.
The sample input Copy
8 3
3 2 6 7 8 3 2 5
3 2 5
Sample output Copy
5
source / classification
#include<stdio.h>
#include<string.h>
#define N 100
/* Find subarray First find the same subscript in the array as the first bit of the subarray i, Then compare If it's different later , Then from i Start looking for */
int main(){
int n,m,k,f,c=0;
int a[N],b[N];
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<m;i++){
scanf("%d",&b[i]);
}
for(int i=0;i<n;i++){
f=1;
// Find the first identical subscript
if(b[0]==a[i]) {
// Start sequential comparison a,b Array , If not, exit the cycle immediately
for(int j=1;j<m;j++){
if(b[j]!=a[i+j]){
f=0;
break;
}
}
// There may be a variety of situations ,c Used to record whether there are subarrays
if(f==1) {
c=1;
printf("%d\n",i);
}
}
}
if(c==0) printf("No Answer\n");
return 0;
}
版权声明
本文为[Qian Qian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210906132300.html
边栏推荐
- ACTF2020 新生赛 Upload 1
- PC微信机器人个人号接口api之实战分析微信同意好友call
- Maya basic tutorial and basic operation explanation
- Error in idea connection to sqlserver
- Grid division [DFS]
- Open3d读写ply点云文件
- PyS1:概述
- Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer--T Li
- Penetration practice - no echo rce thinkphp5 getshell
- Pipy mqtt agent (III) logging
猜你喜欢

深蓝-视觉slam-第六节习题

Detailed explanation of native and H5 mixed development

Getting started with object detection FAQs (deep learning / image classification)

Ue5 little knowledge point animation blueprint interface cannot copy new in editor

Based on ASP Net online flower shopping management

Intranet penetration - proxy penetration - rights lifting - injection - MSF Middleware - domain penetration - log clearing - learning resources

2022年山东省安全员C证考试题及模拟考试

2022年T电梯修理考题及在线模拟考试

2022年主要的编程语言及应用

Meizu, once expected to challenge apple, now lives by providing accessories for Apple users
随机推荐
SurfaceView高性能绘制(四)代码实践篇-绘制多张图片
Convolution operation and cross correlation operation
年金险安全靠谱吗?收益是多少啊?
Handler异步消息传递机制(一)Handler常用基本用法
2022 mobile crane driver examination exercises simulated examination platform operation
性能分析思路
笔记0104. MySQL 高级 - 索引 - 概述
目标检测入门常见问题(深度学习 / 图像分类)
Map Object WeakMap
C#100分秘籍 sduwh
[appium] use the simulator to realize the business functions of Youdao cloud app - add, search, modify and delete
JS -- closure
卷积运算与互相关运算
Implementation of Apache Doris rapid deployment operation and maintenance guide based on ansible
2022化工自动化控制仪表考试练习题及模拟考试
uniapp 热更新和整包更新
2022年T电梯修理考题及在线模拟考试
pyinstaller打包exe(详细教程)
规划自己的健康问题
编程如何提高自己的水平能力?学编程最重要的是什么?请看凡人浅谈如何学C