真 · 人工智障(C++)
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (true) {
cout << "Q: ";
cin >> str;
cout << endl;
int pos1 = str.find("你");
if (pos1 != str.npos) str.replace(pos1, 2, "我");
int pos2 = str.find("是不是");
if (pos2 != str.npos) str.replace(pos2, 6, "是");
int pos3 = str.find("吗");
if (pos3 != str.npos) str.replace(pos3, 2, " ");
int pos4 = str.find("?");
if (pos4 != str.npos) str.replace(pos4, 2, "!");
cout << "A: " << str << endl << endl;
}
return 0;
}
运行效果: