#include\x20\n#include\x20\n#include\x20\n#include\x20\n\nclass\x20NeuralNetwork\x20{\npublic:\n\x20\x20NeuralNetwork()\x20:\x20weights1({{0.5,\x200.3},\x20{0.8,\x200.2}}),\x20weights2({0.4,\x200.9}),\x20bias1({0.1,\x200.1}),\x20bias2(0.1)\x20{}\n\n\x20\x20std::vector\x20predict(std::vector\x20input)\x20{\n\x20\x20\x20\x20std::vector\x20hiddenLayer(outputSize1);\n\x20\x20\x20\x20std::vector\x20outputLayer(outputSize2);\n\n\x20\x20\x20\x20//\x20Hidden\x20Layer\n\x20\x20\x20\x20for\x20(int\x20i\x20=\x200;\x20i\x20<\x20outputSize1;\x20i++)\x20{\n\x20\x20\x20\x20\x20\x20double\x20sum\x20=\x20bias1[i];\n\x20\x20\x20\x20\x20\x20for\x20(int\x20j\x20=\x200;\x20j\x20<\x20inputSize;\x20j++)\x20{\n\x20\x20\x20\x20\x20\x20\x20\x20sum\x20+=\x20input[j]\x20*\x20weights1[j][i];\n\x20\x20\x20\x20\x20\x20}\n\x20\x20\x20\x20\x20\x20hiddenLayer[i]\x20=\x20sigmoid(sum);\n\x20\x20\x20\x20}\n\n\x20\x20\x20\x20//\x20Output\x20Layer\n\x20\x20\x20\x20for\x20(int\x20i\x20=\x200;\x20i\x20<\x20outputSize2;\x20i++)\x20{\n\x20\x20\x20\x20\x20\x20double\x20sum\x20=\x20bias2;\n\x20\x20\x20\x20\x20\x20for\x20(int\x20j\x20=\x200;\x20j\x20<\x20outputSize1;\x20j++)\x20{\n\x20\x20\x20\x20\x20\x20\x20\x20sum\x20+=\x20hiddenLayer[j]\x20*\x20weights2[j];\n\x20\x20\x20\x20\x20\x20}\n\x20\x20\x20\x20\x20\x20outputLayer[i]\x20=\x20sigmoid(sum);\n\x20\x20\x20\x20}\n\n\x20\x20\x20\x20return\x20outputLayer;\n\x20\x20}\n\nprivate:\n\x20\x20std::vector<std::vector>\x20weights1;\n\x20\x20std::vector\x20weights2;\n\x20\x20std::vector\x20bias1;\n\x20\x20double\x20bias2;\n\x20\x20int\x20inputSize\x20=\x2026;\x20//\x20Number\x20of\x20letters\x20in\x20alphabet\n\x20\x20int\x20outputSize1\x20=\x202;\x20//\x20Number\x20of\x20neurons\x20in\x20hidden\x20layer\n\x20\x20int\x20outputSize2\x20=\x202;\x20//\x20Number\x20of\x20neurons\x20in\x20output\x20layer\n\n\x20\x20double\x20sigmoid(double\x20x)\x20{\n\x20\x20\x20\x20return\x201\x20/\x20(1\x20+\x20exp(-x));\n\x20\x20}\n};\n\nclass\x20ChatBot\x20{\npublic:\n\x20\x20ChatBot()\x20:\x20neuralNetwork()\x20{}\n\n\x20\x20std::string\x20getResponse(std::string\x20input)\x20{\n\x20\x20\x20\x20std::vector\x20inputVector;\n\x20\x20\x20\x20for\x20(char\x20c\x20:\x20input)\x20{\n\x20\x20\x20\x20\x20\x20inputVector.push_back((double)(c\x20-\x20'a')\x20/\x20('z'\x20-\x20'a'));\n\x20\x20\x20\x20}\n\n\x20\x20\x20\x20std::vector\x20prediction\x20=\x20neuralNetwork.predict(inputVector);\n\x20\x20\x20\x20double\x20maxProb\x20=\x20std::max(prediction[0],\x20prediction[1]);\n\n\x20\x20\x20\x20if\x20(maxProb\x20==\x20prediction[0])\x20{\n\x20\x20\x20\x20\x20\x20return\x20"是的";\n\x20\x20\x20\x20}else\x20{\n\x20\x20\x20\x20\x20\x20return\x20"不是";\n\x20\x20\x20\x20}\n\x20\x20}\n\nprivate:\n\x20\x20NeuralNetwork\x20neuralNetwork;\n};\n\nint\x20main()\x20{\n\x20\x20ChatBot\x20chatBot;\n\n\x20\x20while\x20(true)\x20{\n\x20\x20\x20\x20std::string\x20input;\n\x20\x20\x20\x20std::cout\x20<<\x20"你的问题:";\n\x20\x20\x20\x20std::getline(std::cin,\x20input);\n\x20\x20\x20\x20std::string\x20response\x20=\x20chatBot.getResponse(input);\n\x20\x20\x20\x20std::cout\x20<<\x20"机器人回答:"\x20<<\x20response\x20<<\x20std::endl;\n\x20\x20}\n\n\x20\x20return\x200;\n