救救我啊
查看原帖
救救我啊
792233
lemon_de_sour_zjc楼主2022/12/19 15:11
#include<bits/stdc++.h>//使用万能头文件
#define M 5//定义M 
using namespace std;//使用标准的名字空间
#define S 15
#define N 30
int LIFE = 30; //猜单词的
string words[S] = {"coding", "programming", "season", "artificial", "painting",
                   "knowledge", "loop", "input", "economics", "ceiling",
                   "absolute", "function", "algorithm", "answer", "intelligence"
                  };
string greet[M] = {"你好少年 ", //回答
                   "地球人你好",
                   "有啥吩咐? ",
                   " 请问我问题 ",
                   "呵呵 "
                  };
string joke[M] = {"    小明买了一本教人如何快速睡着的书,天天看到天亮。",
                  "    我是内蒙古的海军总司令 ",
                  "    法官:你为什么要印假钞?\n    被告无辜地说:因为我不会印真钞。 ",
                  "    贼甲:快数数今天一共抢了多少钱?\n    贼乙:不用,明天看看报纸就知道了。 ",
                  "    妈妈:你的拿手好菜是什么?\n    小红:我烧的...白开水还不错!  "
                 };
string sorry[M] = {"不好意思,我的智商太低听不懂 ",
                   "不好意思,在我的程序里没有这个 ",
                   "这个问题我不准备回答 ",
                   "不好意思,在我的程序里没有这个",
                   "下次再告诉你 "
                  };
string liao[M] = {"你想聊什么,要不你问我问题吧",
                  "你问我问题,我来回!",
                  "你想问我问题吗,来问吧",
                  "要不你来问我问题?",
                  "你来问我问题吧"
                 };
bool allDigits(string s) {
	for (int i = 0; i < s.size(); i++)
		if (s[i] < '0' || s[i] > '9') return 0;
	return 1;
};
void decompose(string s) {
	stringstream ss;
	int n, c = 0;
	ss << s;
	ss >> n;
	if (n <= 1) {
		cout << "    这个数太小了" << n << "我好像分解不了 ***" << endl;
		return;
	}
	for (int i = 2; i * i <= n; i++)
		while (n % i == 0) {
			if (c == 0) {
				cout << "    看看我分解的结果吧,我知道:n等于" << i;
				c++;
			} else cout << "乘以" << i;
			n /= i;
		}
	if (c == 0) cout << "    而且我还知道" << n << "是个质数呢 ***" << endl;
	else if (n > 1) cout << "乘以" << n << " ***" << endl;
	else cout << " ***" << endl;
};
int main() {
	cout << "--------------机器人使用说明书--------------" << endl; //自我介绍
	cout << endl;
	cout << "            嗨,我是娱乐机器人!          " << endl;
	cout << " 请调换到中文输入法,鼠标点击唤醒本窗口" << endl;
	cout << " 你可以在下方光标处随意打字提问" << endl;
	cout << " 提好问后,请按enter键,发送到机器人程序里" << endl;
	cout << " 如果程序知道答案,它会把回答显示到窗口下一行" << endl;
	cout << " 它跳出答案后,你可以在光标处向它继续提问" << endl;
	cout << "         如果你想算数学,请输入:答题      " << endl;
	cout << "       如果你想猜单词,请输入:猜单词    " << endl;
	cout << "  如果你想考验记忆力和眼力,请输入:考验 " << endl;
	cout << " 如果你想出题让我计算24点,请输入:计算24点  " << endl;
	cout << " 如果你想和我的机器人聊天,请输入:聊天  " << endl;
	cout << "      如果你想休息了,你可以输入:结束   " << endl;
	cout << endl;
	cout << "-----------------------------------------" << endl;
	while (1) {
		string s;
		getline(cin, s);
		if (s == "") continue;
		if (s == "结束") //结束指令查询
			break; //退出循环
		else if (s.find("聊") != -1 || s.find("天") != -1) { //聊天回答 ,从聊天机器人MIKE黏贴
			while (1) {
				cout << liao[rand() % M] << endl;
				string s;
				getline(cin, s);
				if (s == "") continue;
				if (s == "结束") //结束指
						
				if (s.find("名") != -1 || s.find("谁") != -1)
					cout << "我的名字叫MIKE,你是我的主人 " << endl;
				else if (s.find("岁") != -1 || s.find("多大") != -1)
					cout << "我今年100岁了,我永远不会死 " << endl;
				else if (s.find("哪里") != -1 || s.find("哪儿") != -1)
					cout << "无处不在 " << endl;
				else if (s.find("会") != -1 || s.find("特长") != -1)
					cout << "我什么都不会,只会聊天" << endl;
				else if (s.find("生") != -1)
					cout << "我生日是2月29日,请送我生日礼物吧 " << endl;
				else if (s.find("智") != -1)
					cout << "我的智商为59,还没有及格 " << endl;
				else if (s.find("球") != -1 || s.find("兴") != -1 || s.find("爱") != -1)
					cout << "我爱看足球,但是不能踢足球,因为我没有腿 " << endl;
				else if (s.find("笑") != -1)
					cout << "我来给你说个笑话吧:" << endl << joke[rand() % M] << endl;
				else if (s.find("你好") != -1)
					cout << greet[rand() % M] << endl;
			}
		} string s;
		else if (s.find("答") != -1 || s.find("题") != -1) { //算数题,从智能出题机器人4.0黏贴
			srand(time(0));
			int s, r, w;
			cout << "请输入你要做题目的数量:";
			cin >> s;
			cout << endl << "请输入数字最大的数(1~400):";
			cin >> r;
			cout << endl << "好的,马上为您出题" << endl << endl;
			int o, v;
			o = 1;
			v = 0;
			while (1) {
				int a = rand() % r + 1;
				int b = rand() % r + 1;
				int c = rand() % r + 1;
				int g = rand() % r + 1;
				int ans = a + b * c - g;
				cout << endl << "第" << o << "题" << endl << a << "+" << b << "*" << c << "-" << g << "=";
				o++;
				int d;
				cin >> d;
				int q, p, h;
				q = 0;
				p = 0;
				int f = 0;
				if (d == ans) {
					cout << "对了!" << endl;
					q++;
					h++;
				} else {
					cout << "错了,下一次再努力!" << endl << "正确答案是:" << ans << endl;
					p++;
					h++;
				}
				cin.get();
				if (h == s) {
					cout << "你对了" << q << "题!" << endl << "你错了" << p << "题" << endl;
					cout << "要继续答题按:1,不要答题的按:2";
					cin >> f;
					if (f == 2) {
						break;
					}
					if (f == 1) {
						s = 0;
						r = 0;
						cout << "请输入你要做题目的数量" << endl;
						cin >> s;
						cout << "请输入数字最大的数(1~400)" << endl;
						cin >> r;
						cout << "好的,马上为您出题" << endl << endl;
					}
				} else if (s.find("猜") != -1 || s.find("单") != -1 || s.find("词") != -1) { //猜单词,从随机版猜单词黏贴
					srand(time(0));
					string ans = words[rand() % s];
					bool ok[N];
					fill(ok, ok + N, 0);
					while (1) {
						cout << "欢迎来到猜单词游戏" << endl;
						cout << "第一个单词是:" << endl;
						int cnt = 0;
						for (int j = 0; j < ans.size(); j++)
							if (ok[j]) {
								cout << " " << ans[j];
								cnt++;
							} else cout << " _";
						cout << endl << endl;
						if (cnt == ans.size())
							break;
						cout << "你还剩余的机会是[" << LIFE << "]次,请输入字母: ";
						char ch;
						cin >> ch;
						int hit = 0;
						for (int j = 0; j < ans.size(); j++)
							if (ans[j] == ch) {
								ok[j] = 1;
								hit = 1;
							}
						if (!hit) LIFE--;
						if (LIFE == 0) break;
						system("cls");
					}
					cout << "正确拼写是 : " << endl;
					for (int j = 0; j < ans.size(); j++)
						cout << " " << ans[j];
				} else if (s.find("考") != -1 || s.find("验") != -1) {
					void SLEEP(int x) { //延时x毫秒
						clock_t now = clock();
						while (clock() - now < x);
						srand(time(0)); //埋下一颗随机种子
						while (1) {
							cout << "请注意屏幕,马上会出现神秘数字!" << endl;
							SLEEP(3000);
							string b, a = "";
							int n = 5;
							for (int i = 0; i < n; i++) {
								char x = rand() % 10 + '0';
								a = a + x;
							}
							cout << a << endl;
							SLEEP(1000); //延时1秒
							system("cls");
							cout << "请输入你看到的数字: ";
							cin >> b;
							if (a == b)
								cout << "完全正确!" << endl;
							else
								cout << "正确答案是: " << a << endl;
							cout << "----------------" << endl;
						}
					} else
						cout << sorry[rand() % M] << endl;
				}
				return 0;
			}

这代码咋了。。。。。。。。。。。。。。救救我啊

2022/12/19 15:11
加载中...