gpt4 book ai didi

c++ - 这不是在 C++ 中使用 bool 运算符吗?

转载 作者:行者123 更新时间:2023-12-01 14:07:05 29 4
gpt4 key购买 nike

我有一些不正确的代码,因为我没有使用 bool 运算符
但是我认为 C++ 中的 bool 运算符是 && 和 ||

这是问题:

Enhance your search algorithm so that a query may contain Boolean operators – AND and OR. For instance, a query “word1 AND word2” means to find all the ideas, each of which contains both of the words. A query “word1 OR word2” means to find all the ideas, each of which contains either word1 or word2.



这是我仅用于 and 运算符的代码
void IdeaBank::AND_searchQuery(string search_word1, string search_word2){

vector <int> match_AND;
for (int i=0;i<newIdea.size();i++)
{
if (newIdea[i].foundWordInBoth(search_word1) && newIdea[i].foundWordInBoth(search_word2))
{
match_AND.push_back(newIdea[i].getID());
}
}

}

我只是将 && 符号更改为 ||检查“或”部分

有什么我遗漏的或者我没有正确使用 bool 运算符吗?

这是我的学校项目,所以我的老师无法给我任何答案。

编辑:
函数 foundWordInBoth 是一个 bool 函数
并且代码没有错误。

我向我的老师展示了我的代码,他说不那样太容易了,你需要使用 bool 运算符,这就是为什么我很困惑

我在网上看了一下,有一些源代码使用 bool 代数来分配 bool 变量编号。
这会是他的意思吗?

编辑:这是我发送电子邮件后得到的回复

bool 表达式不是 bool 运算符。 bool 表达式(公式)是 bool 运算符(AND、OR 和 NOT)的组合。 while 语句或 if 语句中的任何公式都是 bool 表达式。有了 AND 和 OR 的函数后,只需解析表达式,然后组合结果即可。
如果有 AND 和 OR 的函数...是解析表达式以将它们组合成一个函数吗?

有人可以帮忙解释一下吗?

最佳答案

EDIT: the function foundWordInBoth is a boolean function and there is no error with the code.

i showed my teacher my code and he said no that way is too easy you need to use boolean operators, which is why im confused



你的代码对我来说似乎很好。可能您的老师希望您使用按位 bool 运算符 &|而不是逻辑运算符 &&|| .

在那种情况下 true & true = 1 , true | false = 1 ...

关于c++ - 这不是在 C++ 中使用 bool 运算符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61650313/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com