给定一个string数组p及其大小n,同时给定长字符串string s,请返回一个bool数组,元素为true或false对应p中的对应字符串是否为s的子串。要求p中的串长度小于等于8,且p中的串的个数小于等于500,同时要求s的长度小于等于1000。
测试样例:
["a","b","c","d"],4,"abc"
返回:[true,true,true,false]
class Substr {
public:
vector<bool> chkSubStr(vector<string> p, int n, string s) {
// write code here
vector<bool> res;
for(int i = 0; i < n; i++){
if(s.find(p[i]) != -1) res.push_back(true);
else res.push_back(false);
}
return res;
}
};
有关C++字符串中find函数的使用可以看一看这位博主的这篇文章: