请将下面这代码改得更智能#include iostream#include string 函数:根据用户输入返回机器人的回答stdstring getResponseconst stdstring& input stdstring response; 根据用户输入选择回答 if input == 你好 response = 你好有什么可以帮助你的吗?;
#include
// 函数:根据用户输入返回机器人的回答 std::string getResponse(const std::string& input) { std::string response;
// 根据用户输入选择回答
std::string lowercaseInput = input;
std::transform(lowercaseInput.begin(), lowercaseInput.end(), lowercaseInput.begin(), ::tolower); // 将用户输入转换为小写
if (lowercaseInput.find("你好") != std::string::npos) {
response = "你好,有什么可以帮助你的吗?";
} else if (lowercaseInput.find("你叫什么名字") != std::string::npos) {
response = "我是Chat3.0人工智能。";
} else if (lowercaseInput.find("再见") != std::string::npos) {
response = "再见,祝你有个愉快的一天!";
} else {
response = "抱歉,我不明白你的意思。";
}
return response;
}
int main() { std::cout << "Chat3.0人工智能已启动,请开始提问或对话:" << std::endl;
while (true) {
std::string input;
std::getline(std::cin, input); // 获取用户输入
std::string response = getResponse(input); // 获取机器人回答
std::cout << "机器人回答:" << response << std::endl;
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/h6Qo 著作权归作者所有。请勿转载和采集!