Which are in?
来源:互联网 发布:知乎和知网 编辑:程序博客网 时间:2024/06/06 20:40
Which are in?
Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.
Example 1: a1 = [“arp”, “live”, “strong”]
a2 = [“lively”, “alive”, “harp”, “sharp”, “armstrong”]
returns [“arp”, “live”, “strong”]Example 2: a1 = [“tarp”, “mice”, “bull”]
a2 = [“lively”, “alive”, “harp”, “sharp”, “armstrong”]>
returns []
Notes: Arrays are written in “general” notation. See “Your Test Cases” for examples in your language.
Beware: r must be without duplicates.
#include <vector>#include <algorithm>#include <iterator>#include <iostream>class WhichAreIn{public: static std::vector<std::string> inArray(std::vector<std::string> &array1, std::vector<std::string> &array2) { std::vector<std::string> result; std::copy_if(array1.begin(), array1.end(), std::back_inserter(result), [=](std::string str) { std::vector<std::string>::const_iterator it = array2.end(); return std::any_of(array2.begin(), array2.end(), [=](std::string str2) { return str2.find(str) != std::string::npos; }); }); std::sort(result.begin(), result.end(), [](std::string a, std::string b) { return a < b; }); return result; }};int main(){ std::vector<std::string> arr1 = { "live","arp", "strong" }; std::vector<std::string> arr2 = { "lively", "alive", "harp", "sharp", "armstrong" }; std::vector<std::string> sol1 = { "arp", "live", "strong" }; std::vector<std::string> ans1 = WhichAreIn::inArray(arr1, arr2); return 0;}
阅读全文
0 0
- Which are in?
- In which languages are you doing paid work?
- Which OS Are You?
- Question 19: Which of the following are not pre-processor directives in C++?
- Question 36: Which of the following statements regarding functions' default arguments in C++ are correct?
- Question 37: In C++, which of the following statements regarding the code below are valid?
- How to reference JSF managed beans which are provided in a JAR file?
- How to clear the views which are held in the ListView's RecycleBin?
- 45.Which two statements are true about sequences created in a single instance database? (Choose two.
- 117.Which statements are true regarding the WHERE and HAVING clauses in a SELECT statement?
- 121.Which two statements are true regarding the USING clause in table joins? (Choose two .)
- 27.Which two statements are true regarding transactions in an Oracle database? (Choose two.)
- Question 6: Which of the following are container adapters in the STL (Standard Template Library) in C++?
- The DCOM settings which are independent of whether the PC is in a work group or in a domain
- how websites are perceived by their visitors and the basic ways in which websites can be constructed.
- how websites are perceived by their visitors and the basic ways in which websites can be constructed.
- how websites are perceived by their visitors and the basic ways in which websites can be constructed.
- how websites are perceived by their visitors and the basic ways in which websites can be constructed.
- NOJ2214题目解题笔记
- 免费的论文查重网站
- adb shell am broadcast发送广播通知
- 简单DP
- SVM入门(十)将SVM用于多类分类
- Which are in?
- JAVA实现redis超时失效key 的监听触发
- springboot下使用JdbcTemplate和MongoTemplate链接多个mongodb源+sql源
- html非文本只显示一行,多余隐藏的实现
- 聊聊网络游戏同步那点事
- Android MVP 详解(上)
- 希尔排序
- 控制一个div的显示/隐藏
- 关于企业版快递100的坑(M5大32位加密&&请求体某参数Value为Json),加密原理