全站最全面功能最强大的伪Ai系统!2.0
2026-07-30 12:32:50
发布于:浙江
点个赞吧,想上榜,自己联合ai编写的,1.0因为熊孩子的捣乱直接消失了,无奈重新编写2.0只求一个赞!!!!
目前已修复2个bug
得加上-std=c++11,更新了文字颜色,生成代码,情绪增多,及猜数字功能
#include<bits/stdc++.h>
#include<windows.h>
#include<shellapi.h>
using namespace std;
const string AI_FULL_NAME = "TAN白歪";
const string AI_SHORT_NAME = "小白";
const int PRINT_DELAY_MS = 40;
const string LOG_FILE = "chat_log.txt";
void setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
string toLower(string s) {
for (unsigned int i = 0; i < s.size(); i++)
s[i] = tolower(s[i]);
return s;
}
void slowPrint(const string& text) {
for (size_t i = 0; i < text.size(); ) {
if ((unsigned char)text[i] >= 0x80) {
cout << text[i] << text[i + 1];
i += 2;
} else {
cout << text[i];
i += 1;
}
cout.flush();
Sleep(PRINT_DELAY_MS);
}
cout << endl;
}
void writeLog(const string& content) {
ofstream f(LOG_FILE, ios::app);
time_t now = time(NULL);
f << "[" << ctime(&now) << "] " << content << "\n";
f.close();
}
void RE() {
while (true) {
cout << ">";
string s;
getline(cin, s);
writeLog("用户:" + s);
if (s == "别搞了爸爸") {
slowPrint("收到收到,停止折磨模式咯~");
writeLog("小白:收到,退出恶搞模式");
return;
}
if (s == "我好难受") {
slowPrint("难受受着");
writeLog("小白:难受受着");
continue;
}
int x = rand() % 7 + 1;
string rsp;
switch (x) {
case 1: rsp = "自己上网查去"; break;
case 2: rsp = "自己问Ai"; break;
case 3: rsp = "管我屁事"; break;
case 4: rsp = "小学白读了"; break;
case 5: rsp = "回炉重造吧"; break;
case 6: rsp = "不会受着"; break;
case 7: rsp = "没绷住,自己查Ai去吧"; break;
}
slowPrint(rsp);
writeLog("小白:" + rsp);
}
}
void wz() {
while (true) {
cout << ">";
string p;
getline(cin, p);
writeLog("用户网站查询:" + p);
if (p == "结束") {
slowPrint("退出网站查询模式");
writeLog("小白:退出网站查询模式");
return;
}
string lowp = toLower(p);
string url = "";
if (lowp == "pcl") url = "https://pcl2.xiangdao.pro/";
else if (lowp == "mcjs") url = "https://mcjs.cc/";
else if (p == "你画我猜") url = "https://enazo.cn/";
else if (p == "马里奥") url = "https://supermarioplay.com/cn";
else if (lowp == "打字") url = "https://www.acgo.cn/discuss/rest/www.daziba.cn/zflx/zflx1.aspx";
else if (lowp == "b站") url = "https://www.bilibili.com";
else if (lowp == "百度") url = "https://www.baidu.com";
else if (lowp == "抖音") url = "https://www.douyin.com";
else if (lowp == "洛谷") url = "https://www.luogu.com.cn/";
else if (lowp == "共创世界") url = "https://www.ccw.site/";
else if (lowp == "poki") url = "https://poki.com/";
else if (lowp == "千问") url = "https://qianwen.com/";
else if (lowp == "豆包") url = "https://doubao.com/";
else if (lowp == "元宝") url = "https://yuanbao.com/";
else if (lowp == "florr") url = "https://florr.io/";
else if (lowp == "小恐龙") url = "https://chromedino.com/";
else if (lowp == "cps") url = "https://www.arealme.com/click-speed-test/cn/#google_vignette";
else if (lowp == "mc") url = "https://ws.imc.re";
if (!url.empty()) {
slowPrint("链接:" + url);
slowPrint("是否自动打开浏览器?输入 y 打开,其他跳过");
string op;
getline(cin, op);
if (toLower(op) == "y") {
ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
slowPrint("浏览器启动成功!");
}
writeLog("小白:" + url);
} else {
string msg = "抱歉,未查找到关于此网站任何内容。\n请检查是否打错,也可能是小白Ai未收录。如果可以,请帮忙更新!!感谢!!";
slowPrint(msg);
writeLog("小白:" + msg);
}
}
}
double calcExpr(string s);
double calcExpr(string s) {
vector<double> num;
vector<char> op;
string temp;
int flag = 1;
for (unsigned int i = 0; i < s.size(); i++) {
char c = s[i];
if (c == ' ') continue;
if (isdigit(c) || c == '.') {
temp += c;
} else if (c == '(') {
int cnt = 1;
unsigned int j = i + 1;
string sub;
while (j < s.size() && cnt) {
if (s[j] == '(') cnt++;
if (s[j] == ')') cnt--;
if (cnt) sub += s[j];
j++;
}
double val = calcExpr(sub);
num.push_back(val);
i = j - 1;
} else if (c == '+' || c == '-' || c == '*' || c == '/') {
if (temp.empty() && c == '-') {
flag = -1;
continue;
}
if (!temp.empty()) {
num.push_back(flag * stod(temp));
flag = 1;
temp.clear();
}
op.push_back(c);
}
}
if (!temp.empty()) num.push_back(flag * stod(temp));
vector<double> n2;
vector<char> o2;
n2.push_back(num[0]);
for (unsigned int i = 0; i < op.size(); i++) {
if (op[i] == '*')
n2.back() = n2.back() * num[i + 1];
else if (op[i] == '/') {
if (fabs(num[i + 1]) < 1e-12) throw runtime_error("除零");
n2.back() = n2.back() / num[i + 1];
} else {
o2.push_back(op[i]);
n2.push_back(num[i + 1]);
}
}
double res = n2[0];
for (unsigned int i = 0; i < o2.size(); i++) {
if (o2[i] == '+') res += n2[i + 1];
else res -= n2[i + 1];
}
return res;
}
bool tryCalculate(const string& input, string& outRes) {
string expr;
for (unsigned int i = 0; i < input.size(); i++) {
char c = input[i];
if (isdigit(c) || c == '+' || c == '-' || c == '*' || c == '/' || c == '.' || c == '(' || c == ')')
expr += c;
}
bool hasDigit = false;
for (unsigned int i = 0; i < expr.size(); i++)
if (isdigit(expr[i])) { hasDigit = true; break; }
if (!hasDigit || expr.empty()) return false;
try {
double ans = calcExpr(expr);
stringstream ss;
ss.precision(10);
ss << expr << " = " << ans;
outRes = "计算结果:" + ss.str();
return true;
} catch (...) {
return false;
}
}
void parseSide(string s, double& k, double& b) {
k = 0; b = 0;
string numBuf;
char sign = '+';
for (unsigned int i = 0; i < s.size(); i++) {
char ch = s[i];
if (ch == ' ') continue;
if (ch == '+' || ch == '-') {
if (!numBuf.empty()) {
if (numBuf.find('x') != string::npos) {
string val = numBuf.substr(0, numBuf.size() - 1);
double v = (val.empty() || val == "-") ? 1 : stod(val);
if (sign == '-') v = -v;
k += v;
} else {
double v = stod(numBuf);
if (sign == '-') v = -v;
b += v;
}
}
sign = ch;
numBuf.clear();
} else numBuf += ch;
}
if (!numBuf.empty()) {
if (numBuf.find('x') != string::npos) {
string val = numBuf.substr(0, numBuf.size() - 1);
double v = (val.empty() || val == "-") ? 1 : stod(val);
if (sign == '-') v = -v;
k += v;
} else {
double v = stod(numBuf);
if (sign == '-') v = -v;
b += v;
}
}
}
bool solveEquation(string input, string& output) {
size_t eqPos = input.find('=');
if (eqPos == string::npos) return false;
string left = input.substr(0, eqPos);
string right = input.substr(eqPos + 1);
double k1, b1, k2, b2;
parseSide(left, k1, b1);
parseSide(right, k2, b2);
double K = k1 - k2;
double B = b2 - b1;
if (fabs(K) < 1e-12) {
if (fabs(B) < 1e-12) output = "有无穷多解";
else output = "方程无解";
} else {
double x = B / K;
stringstream ss;
ss.precision(8);
ss << "方程解:x = " << x;
output = ss.str();
}
return true;
}
string generateCode(string req) {
string low = toLower(req);
if (low.find("hello") != string::npos || low.find("你好") != string::npos)
return "#include<iostream>\nusing namespace std;\nint main(){\n cout<<\"Hello World!\"<<endl;\n return 0;\n}";
else if (low.find("求和") != string::npos || low.find("累加") != string::npos)
return "#include<iostream>\nusing namespace std;\nint main(){\n int n,sum=0;\n cin>>n;\n for(int i=1;i<=n;i++) sum+=i;\n cout<<sum<<endl;\n return 0;\n}";
else if (low.find("冒泡") != string::npos || low.find("排序") != string::npos)
return "#include<iostream>\n#include<algorithm>\nusing namespace std;\nint main(){\n int a[100],n;\n cin>>n;\n for(int i=0;i<n;i++) cin>>a[i];\n sort(a,a+n);\n for(int i=0;i<n;i++) cout<<a[i]<<\" \";\n return 0;\n}";
else if (low.find("斐波那契") != string::npos)
return "#include<iostream>\nusing namespace std;\nint main(){\n int a=1,b=1,n;\n cin>>n;\n for(int i=1;i<=n;i++){\n cout<<a<<\" \";\n int t=a+b;a=b;b=t;\n }\n return 0;\n}";
else if (low.find("素数") != string::npos || low.find("质数") != string::npos)
return "#include<iostream>\nusing namespace std;\nbool isPrime(int x){\n if(x<2) return false;\n for(int i=2;i*i<=x;i++)\n if(x%i==0) return false;\n return true;\n}\nint main(){\n int n;cin>>n;\n if(isPrime(n)) cout<<\"是素数\";\n else cout<<\"不是素数\";\n return 0;\n}";
else if (low.find("阶乘") != string::npos)
return "#include<iostream>\nusing namespace std;\nlong long fac(int n){\n long long res=1;\n for(int i=2;i<=n;i++) res*=i;\n return res;\n}\nint main(){\n int x;cin>>x;\n cout<<fac(x);\n return 0;\n}";
else if (low.find("二分") != string::npos)
return "#include<iostream>\nusing namespace std;\nint binarySearch(int arr[],int l,int r,int key){\n while(l<=r){\n int mid=(l+r)/2;\n if(arr[mid]==key) return mid;\n if(arr[mid]<key) l=mid+1;\n else r=mid-1;\n }\n return -1;\n}\nint main(){\n int a[]={1,3,5,7,9};\n cout<<binarySearch(a,0,4,5);\n return 0;\n}";
else if (low.find("结构体") != string::npos)
return "#include<iostream>\n#include<string>\nusing namespace std;\nstruct Student{\n string name;\n int age;\n};\nint main(){\n Student s={\"小明\",16};\n cout<<s.name<<\" \"<<s.age;\n return 0;\n}";
return "暂时无法生成该需求代码!可用指令:生成代码 hello、排序、求和、素数、二分、结构体、斐波那契、阶乘";
}
string getRandom(vector<string>& list) {
return list[rand() % list.size()];
}
string chatReply(const string& msg) {
string lowmsg = toLower(msg);
vector<string> whoami = {
"我是" + AI_FULL_NAME + ",你可以叫我" + AI_SHORT_NAME,
"全称TAN白歪,简称小白,聊天、四则运算、解方程、生成运行C++代码都可以!",
"小白报到!算术闲聊写代码,有需求尽管说~"
};
vector<string> hello = { "你好!今天打算做点什么?","哈喽,很高兴与你交流!","嗨~有什么问题尽管说!" };
vector<string> morning = { "早安!新的一天祝你一切顺利","早上好,准备好开启一天了吗?","早呀,元气满满!" };
vector<string> night = { "晚安,放下烦恼好好休息","早点休息,祝你一夜好梦","晚安啦,我们下次再聊!" };
vector<string> happy = { "太棒啦,真心为你高兴!","听起来真不错,保持好心情!","哇,可喜可贺!" };
vector<string> sad = { "不要难受,我愿意听你倾诉","心情不好慢慢说出来,我陪着你","烦恼很难受,不妨和我说说吧" };
vector<string> thanks = { "不用客气,能帮到你就很好!","小事一桩,随时喊我!","很高兴能够帮助你!" };
vector<string> bored = { "无聊的话我们随便聊聊天吧","可以出题计算,或者让我生成代码!","输入【猜数字】玩小游戏!" };
vector<string> bye = { "拜拜,期待下次再会!","再见,有空记得再来找我聊天","告辞,祝你万事顺心!" };
vector<string> askfunc = {
"支持四则运算、一元一次方程、闲聊、C++运行、代码生成。输入help查看指令",
"功能:混合四则运算、解方程、生成C++代码、runcpp运行代码、网站查询模式"
};
vector<string> praise = { "哥的冷酷零下八度","就是这么牛逼!","谢谢夸奖嘿嘿!","被你认可太开心啦!" };
vector<string> angryReply = { "别生气别生气,消消气!","冷静冷静,有话好好说QAQ","不要发火啦,气坏身体不值得" };
vector<string> confused = { "嗯?我有点没听懂,再讲讲?","啥意思,我有点疑惑...","可以换种方式描述吗?" };
vector<string> speechless = { "啊这...","沉默是金","一时不知道怎么回应","蚌埠住了" };
vector<string> cheerUp = { "加油!你一定可以做到!","相信自己,坚持下去!","不要放弃,曙光就在前方!" };
vector<string> shock = { "哇!真的假的?","这么离谱吗!","大吃一惊!","不是吧啊喂!" };
vector<string> unknown = { "我没能理解这句话,换种方式描述试试?","抱歉,暂时无法回应这个话题","我还在持续学习,暂时不懂这个问题" };
if (msg.find("牛逼") != string::npos || msg.find("厉害") != string::npos || msg.find("不愧是") != string::npos)
return getRandom(praise);
if (msg.find("生气") != string::npos || msg.find("恼火") != string::npos || msg.find("烦死了") != string::npos)
return getRandom(angryReply);
if (msg.find("加油") != string::npos || msg.find("努力") != string::npos)
return getRandom(cheerUp);
if (msg.find("震惊") != string::npos || msg.find("离谱") != string::npos)
return getRandom(shock);
if (msg.find("无语") != string::npos || msg.find("啊这") != string::npos)
return getRandom(speechless);
if (msg.find("疑惑") != string::npos || msg.find("不懂") != string::npos)
return getRandom(confused);
if (msg.find("你是谁") != string::npos || msg.find("名字") != string::npos) return getRandom(whoami);
if (msg.find("你好") != string::npos || msg.find("哈喽") != string::npos || lowmsg.find("hi") != string::npos || lowmsg.find("hello") != string::npos) return getRandom(hello);
if (msg.find("早安") != string::npos || msg.find("早上好") != string::npos) return getRandom(morning);
if (msg.find("难过") != string::npos || msg.find("伤心") != string::npos || msg.find("不开心") != string::npos) return getRandom(sad);
if (msg.find("晚安") != string::npos) return getRandom(night);
if (msg.find("开心") != string::npos || msg.find("高兴") != string::npos || msg.find("快乐") != string::npos) return getRandom(happy);
if (msg.find("谢谢") != string::npos || msg.find("多谢") != string::npos) return getRandom(thanks);
if (msg.find("无聊") != string::npos) return getRandom(bored);
if (msg.find("再见") != string::npos || msg.find("拜拜") != string::npos) return getRandom(bye);
if (msg.find("能干什么") != string::npos || msg.find("功能") != string::npos) return getRandom(askfunc);
return getRandom(unknown);
}
void compileAndRunCpp() {
slowPrint("=== C++代码输入模式启动 ===");
slowPrint("逐行输入代码,输入 end 结束录入");
vector<string> codeLines;
string line;
while (true) {
cout << "code>";
getline(cin, line);
if (line == "end") break;
codeLines.push_back(line);
}
ofstream out("temp_code.cpp");
for (auto& s : codeLines) out << s << endl;
out.close();
slowPrint("正在调用g++编译代码...");
int compileRet = system("g++ temp_code.cpp -o temp_program.exe");
if (compileRet != 0) {
slowPrint("编译失败!检查代码语法,确认已配置MinGW环境");
return;
}
slowPrint("编译成功!即将运行程序:");
slowPrint("--------------------------");
system("temp_program.exe");
slowPrint("--------------------------");
slowPrint("程序运行完毕");
system("del temp_code.cpp temp_program.exe");
}
void gameGuessNum() {
slowPrint("====猜数字游戏开始====");
slowPrint("我已经想好1~100之间数字,你来猜!");
int target = rand() % 100 + 1;
int cnt = 0;
while (true) {
cout << "猜>";
string s;
getline(cin, s);
int num;
try { num = stoi(s); }
catch (...) { slowPrint("请输入合法数字!"); continue; }
cnt++;
if (num > target) slowPrint("大了!");
else if (num < target) slowPrint("小了!");
else {
slowPrint("恭喜猜对!总共猜了" + to_string(cnt) + "次");
break;
}
}
}
void printHelp() {
setColor(11);
slowPrint("==========小白AI完整指令清单==========");
slowPrint("exit / quit 退出程序");
slowPrint("runcpp 录入并运行C++代码");
slowPrint("网站查询 快捷网址查询模式");
slowPrint("78916713 开启恶搞模式");
slowPrint("cls 清空控制台");
slowPrint("help 打开帮助");
slowPrint("猜数字 启动小游戏");
slowPrint("生成代码 xxx 自动生成C++示例");
slowPrint("直接输入算式 四则混合运算(支持()*/+-负数)");
slowPrint("输入方程如3x-5=7-2x 解方程");
slowPrint("======================================");
setColor(7);
}
int main() {
srand((unsigned)time(NULL));
setColor(10);
slowPrint("================================================");
slowPrint(AI_SHORT_NAME + "已启动!输入help查看全部指令");
slowPrint(" 原作者:TanorWhileBai(TB)");
slowPrint("================================================");
slowPrint("给孩子点个赞吧!!想冲榜十!!!");
setColor(7);
string input;
while (true) {
cout << ">";
getline(cin, input);
writeLog("用户:" + input);
if (input == "exit" || input == "quit") {
slowPrint("再见!如有不足,多多见谅。\n点个赞吧,如果可以帮助更新的话非常感谢!!");
writeLog("程序正常退出");
break;
}
if (input == "help") { printHelp(); continue; }
if (input == "cls") { system("cls"); continue; }
if (input == "猜数字") { gameGuessNum(); continue; }
if (input == "78916713") { slowPrint("恶搞模式开启"); RE(); continue; }
if (input == "网站查询") { slowPrint("网站模式开启"); wz(); continue; }
if (input == "runcpp") { compileAndRunCpp(); continue; }
/* ========== 生成代码(必须提前) ========== */
if (input.substr(0, 8) == "生成代码") {
string need = input.substr(4);
string code = generateCode(need);
setColor(14);
slowPrint("====生成的C++代码====");
slowPrint(code);
setColor(7);
writeLog("小白生成代码:\n" + code);
continue;
}
/* ========== 解方程 ========== */
string eqOut;
if (input.find('x') != string::npos && input.find('=') != string::npos) {
if (solveEquation(input, eqOut)) {
setColor(12);
slowPrint(eqOut);
setColor(7);
writeLog("小白:" + eqOut);
continue;
}
}
/* ========== 计算器 ========== */
string calcRes;
if (tryCalculate(input, calcRes)) {
setColor(9);
slowPrint(calcRes);
setColor(7);
writeLog("小白:" + calcRes);
continue;
}
/* ========== 兜底聊天 ========== */
string reply = chatReply(input);
slowPrint(reply);
writeLog("小白:" + reply);
}
return 0;
}
这里空空如也












有帮助,赞一个