描述

使用STL中的search函数,判断一个序列是否是另一个序列的子序列。

部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码。

int main()
{
vector<int> vec1, vec2;
int n, m, a;
cin>>n>>m;
while(n--)
{
cin>>a;
vec1.push_back(a);
}
while(m--)
{
cin>>a;
vec2.push_back(a);
}
Check(vec1, vec2);
return 0;
}

输入

第一行为一个正整数n和m,n和m为元素个数(n<=1000)。

第二行有n个整数,表示序列1的所有元素。

第三行有m个整数,表示序列2的所有元素。

输出

如果序列2是序列1的子序列,则输出所在子序列的始末位置。

否则输出None。

样例输入

5 2
1 3 2 4 5
3 2

样例输出

2 3

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void Check(vector<int > &vec1,vector<int> &vec2)
{
vector<int >::iterator iter1,iter2;
int k=;
for(iter2=vec2.begin();iter2!=vec2.end();iter2++)
k++;
iter1=search(vec1.begin(),vec1.end(),vec2.begin(),vec2.end());
if(iter1!=vec1.end()) cout<<int(iter1-vec1.begin())+<<" "<<int(iter1-vec1.begin())+k<<endl;
else cout<<"None"<<endl;
}
int main()
{
vector<int> vec1, vec2;
int n, m, a;
cin>>n>>m;
while(n--)
{
cin>>a;
vec1.push_back(a);
}
while(m--)
{
cin>>a;
vec2.push_back(a);
}
Check(vec1, vec2);
return ;
}

STL之search的更多相关文章

  1. stl binary search

    stl binary search */--> pre { background-color: #2f4f4f;line-height: 1.6; FONT: 10.5pt Consola,&q ...

  2. leetcode@ [34] Search for a Range (STL Binary Search)

    https://leetcode.com/problems/search-for-a-range/ Given a sorted array of integers, find the startin ...

  3. C++ STL Binary search详解

    一.解释 以前遇到二分的题目都是手动实现二分,不得不说错误比较多,关于返回值,关于区间的左闭右开等很容易出错,最近做题发现直接使用STL中的二分函数方便快捷还不会出错,不过对于没有接触过的同学,二分函 ...

  4. c++ STL find search

    #include <iostream>#include <algorithm>#include <deque>#include <list>#inclu ...

  5. STL 简介,标准模板库

    这篇文章是关于C++语言的一个新的扩展--标准模板库的(Standard Template Library),也叫STL.  当我第一次打算写一篇关于STL的文章的时候,我不得不承认我当时低估了这个话 ...

  6. STL中list用法

    本文以List容器为例子,介绍了STL的基本内容,从容器到迭代器,再到普通函数,而且例子丰富,通俗易懂.不失为STL的入门文章,新手不容错过! 0 前言 1 定义一个list 2 使用list的成员函 ...

  7. STL list链表的用法详解

    本文以List容器为例子,介绍了STL的基本内容,从容器到迭代器,再到普通函数,而且例子丰富,通俗易懂.不失为STL的入门文章,新手不容错过! 0 前言 1 定义一个list 2 使用list的成员函 ...

  8. list用法详解

    在这里感谢大牛们的奉献!此致敬礼! 本文转载自百度文库.作者如下.其中下面的count, count_if等函数的使用有些陈旧,如在编译时遇到问题,请百度. 标准模板库(STL)介绍 作者:Scott ...

  9. AwesomePerfCpp 性能优化

    Contents Talks Articles Sites/Blogs Tools Libraries Books About Talks 2013: Going Native 2013 - Andr ...

随机推荐

  1. bzoj 2566 calc 拉格朗日插值

    calc Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 377  Solved: 226[Submit][Status][Discuss] Descr ...

  2. ext4文件系统由文件的inode号定位其inode Table

    在ubuntu中(以16.06为例),stat filename 可以查看文件的inode数值,但是如何确定该inode项具体在哪个块组下的inode Table中不是那么容易,接下来通过一步步计算来 ...

  3. 《vue.js实战》练习---标签页组件

    html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  4. 关于UML

    http://www.cnblogs.com/zfc2201/archive/2011/08/16/2141433.html

  5. 归档普通对象Demo示例程序源代码

    源代码下载链接:06-归档普通对象.zip34.2 KB // MJPerson.h // //  MJPerson.h //  06-归档普通对象 // //  Created by apple o ...

  6. python configparse

    # 参考:https://www.cnblogs.com/lily1989/p/8401005.html # https://blog.csdn.net/willhuo/article/details ...

  7. python3 闭包函数,装饰器

    闭包函数: 1.定义在函数内部的函数 2.包含对外部作用域而非全局作用域的引用特点: 1.自带作用域 2.延迟计算(取到内存地址,加括号执行) def 外部函数(func): def 内部函数(*ar ...

  8. 转:js中javascript:void(0) 真正含义

    from:http://www.jb51.net/article/71532.htm 在Javascript中void是一个操作符,该操作符指定要计算一个表达式但是不返回值. 我想使用过ajax的都常 ...

  9. How to learn wxPython

    目录 How to learn wxPython Learn Python Choose a good editor Install wxPython Read the wxPython tutori ...

  10. KVM基本概念

    在kvm技术中,应用到的两个东西:qemu和kvm.其中kvm负责cpu虚拟化和内存虚拟化,但是kvm不能模拟其他设备,qemu是模拟IO设备(网卡,磁盘),kvm加上qemu之后就能实现真正意义上的 ...