部分名称搜索
Partial Name Search
本文关键字:搜索 更新时间:2023-10-16
有人能给我一个如何进行部分名称搜索或使搜索不区分大小写的例子吗。我键入了这些函数来按姓氏搜索,但我想知道如何进行部分名称搜索/不区分大小写。谢谢
int Search()
{
for(int i = 0 ; i < Size ; i++)
if (Target == List[i].LastName)
return i;
return -1;
}
void LookUp_Student()
{
string Target;
int Index;
cout << "nEnter a name to search for (Last Name): ";
getline(cin,Target);
Index = Search(List,Size,Target);
if (Index == -1)
cout << Target <<" is not on the list.n" ;
else
Print_Search(List[Index]);
}
您可以使用自定义函数进行字符串大小写不敏感比较:
#include <algorithm>
//...
bool compare_str(const string& lhs, const string& rhs)
{
return lhs.size() == rhs.size() &&
std::equal(lhs.begin(), lhs.end(), rhs.begin(),
// Lambda function
[](const char& x, const char& y) {
// Use tolower or toupper
return toupper(x) == toupper(y);
}
);
}
然后像这样使用:
if (compare_str(Target,List[i].LastName) )
{
// a match
}
参考:std::equal
相关文章:
- 有根的二进制搜索树.保留与其父级的链接
- 在C++中搜索嵌套多映射值
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 正在尝试重载二进制搜索树分配运算符
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 向量上的线性搜索
- 如何在动态数组上使用搜索函数
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- cmake:添加要搜索头文件的目录
- 使用C++创建特殊的二叉搜索树
- 在C++的字符串中搜索和删除某些字符
- std::unordered_map 搜索算法是如何实现的?
- 使用不变量来确定二分搜索中的边界条件
- 二叉搜索如何比线性搜索更快?
- 按边长度递归搜索图中所有可行路径
- QStackWidget - 按名称搜索
- 在递归二叉搜索树中搜索
- 我的二进制搜索程序只是关闭了