最新研究成果——大鹅通~
2025-08-07 20:40:06
发布于:浙江
是否因为计算出错而烦恼?
是否想在课上比其他同学快一步算出答案?
是否想拥有一个兼游戏和计算一体的程序?
最新研究成果——大鹅通为您献上!
下面是代码:
#include<bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
#define ll long long
map<string,string> string_list;
map<string,ll> int_list;
map<string,short> cv; //0为不存在,1为数字类型,2为字符串类型
vector<string> name;
bool run=1;
bool run_type=0; //0为短运行模式,1为长运行模式
vector<string> running_things;
//----------------------字体颜色区----------------------
void color(const char* s, int color){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
//----------------------字体颜色区底----------------------
//----------------------随机数字区----------------------
unsigned int random(int i,int j){
random_device rad;
unsigned int ST = rad();
mt19937 Shuai_Tong(ST);
return Shuai_Tong()%(j-i+1)+i;
}
//----------------------随机数字区底----------------------
//----------------------猜数字区----------------------
void guess_numbers(){
color("~~~~~~~~~~~~~~~~~~~~猜数字——大鹅版~~~~~~~~~~~~~~~~~~~~",6);
cout<<"\n";
cout<<"若加入玩家输入,输入@为结束:\n";
while(1){
string nm;
cout<<name.size()+1<<'.';
cin>>nm;
if(nm=="@"){
if(name.size()==0){
cout<<"否定!不能这样哦!\n";
}
else break;
}
else name.push_back(nm);
}
system("cls");
while(1){
vector<int> fen(name.size()+1);
int easy=1,card=1,cos=1,buff=0;
int l=1,r=0,in=0;
ll ans=0;
double bi=1;
string win="";
while(1){
char sz=' ';
color("~~~~~~~~~~~~~~~~~~~~猜数字——大鹅版~~~~~~~~~~~~~~~~~~~~",6);
cout<<"endl";
cout<<"tips:通过数字键或w,a,s,d控制参数,回车为完成.\n";
cout<<"难度:"<<easy;
if(cos==1) cout<<" <-";
cout<<endl;
cout<<"困难卡牌:"<<card;
if(cos==2) cout<<" <-";
cout<<endl;
cout<<"退出游戏:";
if(cos==3) cout<<" <-";
cout<<endl;
loop:
sz=getch();
if(sz==13){
if(cos==3) return ;
break;
}
else if(sz=='w') cos=((cos==1)?3:cos-1);
else if(sz=='s') cos=((cos==3)?1:cos+1);
else if(sz=='a'&&cos==1) easy=((easy==1)?6:easy-1);
else if(sz=='d'&&cos==1) easy=((easy==6)?1:easy+1);
else if(sz=='a'&&cos==2) card=((card==1)?6:card-1);
else if(sz=='d'&&cos==2) card=((card==6)?1:card+1);
else if(sz>='1'&&sz<='6'&&cos==1) easy=sz-'0';
else if(sz>='1'&&sz<='6'&&cos==2) card=sz-'0';
else goto loop;
system("cls");
}
system("cls");
if(easy==1) r=100;
else if(easy==2) r=1000;
else if(easy==3) r=5000;
else if(easy==4) r=10000;
else if(easy==5) r=50000;
else if(easy==6) r=100000;
int rr=r;
ans=random(l,r);
int last=-1;
string last_name="";
bool ok=0;
while(1){
for(auto it:name){
if(buff==1){
ans+=random(2,20);
l+=2;
r+=20;
buff=0;
}
if(buff==2){
ans-=random(2,20);
l-=20;
r-=2;
buff=0;
}
cout<<"目前范围:"<<l<<'~'<<r<<';'<<endl<<endl;
cout<<"前一次:\n\n";
if(last==-1){
cout<<"前一个答案被作者吃掉啦!┗|`O′|┛ 嗷~~";
}
else if(buff==5){
cout<<"前一个答案被小猴抹黑啦!(っ °Д °;)っ";
buff=0;
}
else{
cout<<last_name<<" 猜测数字:"<<last<<endl;
if(last<ans) cout<<last_name<<' '<<"回答错误!猜小了!\n";
else if(last>ans)cout<<last_name<<' '<<"回答错误!猜大了!\n";
double cha=(abs(ans-last)*100.0/rr);
if(cha<=0.05){
color("决胜局了!",4);
}
else if(cha<=5){
color("一步之遥",5);
}
else if(cha<=10){
color("近在眼前",9);
}
else if(cha<=20){
color("相差不远了",6);
}
else if(cha<=30){
color("仰望莫及",11);
}
else{
color("远在天边",7);
}
}
cout<<endl<<endl<<endl;
cout<<"现在:\n\n";
last_name=it;
if(buff==3){
buff=0;
cout<<"你这回合被跳过啦!欸嘿~";
system("cls");
continue;
}
if(buff==4){
buff=0;
cout<<"你这一回合由聪明的小猴自动选择!\n";
in=(l+r)/2;
cout<<"小猴替 "<<it<<" 选择了 "<<in<<" !\n";
}
else{
cout<<"请 "<<it<<" 输入猜测数字:";
cin>>in;
if(buff==6){
cout<<"小猴帮你宽松了答案!\n你的答案变为 ";
if(abs(ans-in)<=3){
in=ans;
}
else{
if(in<ans) in+=3;
else in-=3;
}
cout<<in<<" !\n";
buff=0;
}
}
if(in<l||in>r){
cout<<"不合理啦!啃掉你的答案!嗷!";
getch();
system("cls");
continue;
}
else if(in==ans){
win=it;
ok=1;
break;
}
else{
last=in;
if(in<ans){
cout<<it<<' '<<"回答错误!猜小了!\n";
l=in+1;
}
else if(in>ans){
cout<<it<<' '<<"回答错误!猜大了!\n";
r=in-1;
}
double cha=(abs(ans-in)*100.0/rr);
if(cha<=0.05){
color("决胜局了!",4);
}
else if(cha<=5){
color("一步之遥",5);
}
else if(cha<=10){
color("近在眼前",9);
}
else if(cha<=20){
color("相差不远了",6);
}
else if(cha<=30){
color("仰望莫及",11);
}
else{
color("远在天边",7);
}
}
getch();
if(random(1,7-card)==1){
cout<<"\n噢!调皮的小猴打出了一张魔法牌!\n是什么牌呢……";
getch();
cout<<"\n哇哦!是[";
vector<string> card_list(10);
card_list[1]="增数";
card_list[2]="减数";
card_list[3]="跳过";
card_list[4]="自动选择";
card_list[5]="抹黑";
card_list[6]="宽松";
int left=1,right=6;
int out_card=random(1,6);
buff=out_card;
cout<<card_list[out_card]<<"牌]!\n下一回合的玩家将享受到此牌效果!";
getch();
}
system("cls");
}
if(ok==1) break;
}
cout<<win<<' '<<"是赢家!!芜湖!";
getch();
system("cls");
}
return ;
}
//----------------------猜数字区底----------------------
//----------------------选择游戏区----------------------
void choose_game(){
system("cls");
cout<<"~~~~~~~~~~游戏区~~~~~~~~~~\n";
cout<<"请选择你要游玩的游戏:\n";
cout<<" 1.猜数字(升级版)\n";
cout<<" 请选择:";
int choose_=0;
cin>>choose_;
system("cls");
if(choose_==1) guess_numbers();
else{
color("GameError:未知游戏编号",4);
}
return ;
}
//----------------------选择游戏区底----------------------
//----------------------转义字符更改区----------------------
string turn_char(string old){
int i=0;
string new_="";
string name="";
int many=0;
for(i=0;i<old.size()-1;i++){
if(old[i]=='\\'&&old[i+1]=='\\') new_+='\\';
else if(old[i]=='\\'&&old[i+1]=='\'') new_+='\'';
else if(old[i]=='\\'&&old[i+1]=='\"') new_+='\"';
else if(old[i]=='\\'&&old[i+1]=='?') new_+='\?';
else if(old[i]=='\\'&&old[i+1]=='a') new_+='\a';
else if(old[i]=='\\'&&old[i+1]=='b') new_+='\b';
else if(old[i]=='\\'&&old[i+1]=='f') new_+='\f';
else if(old[i]=='\\'&&old[i+1]=='n') new_+='\n';
else if(old[i]=='\\'&&old[i+1]=='r') new_+='\r';
else if(old[i]=='\\'&&old[i+1]=='t') new_+='\t';
else if(old[i]=='\\'&&old[i+1]=='v') new_+='\v';
else if(old[i]=='\\'&&old[i+1]=='0') new_+='\0';
else{
new_+=old[i];
continue;
}
i+=1;
}
if(i==old.size()-1) new_+=old[old.size()-1];
return new_;
}
//----------------------转义字符更改区----------------------
//----------------------KMP辅助输入区(未完成)----------------------
int find(string a,string b){
int fi=a.find(b,0);
if(fi==-1) return -1;
return fi;
}
//----------------------KMP辅助输入区底(未完成)----------------------
//----------------------计算区----------------------
int bad=0;
/*
bad=0 OK
bad=1 除数错误
bad=2 括号错误
bad=3 括号内或算式为空
24=2*2*2*3
6 2 2
5**-5 = (1/5)**5
*/
bool is_fu(char it){
if(it=='+'||it=='-'||it=='*'||it=='/'||it=='%'||it=='&'||it=='^'||it=='|'||it=='O'||it=='A'||it=='P') return 1;
return 0;
}
int best(char snow){
if(snow=='O') return 1;
if(snow=='A') return 2;
if(snow=='|') return 3;
if(snow=='^') return 4;
if(snow=='&') return 5;
if(snow=='+'||snow=='-') return 6;
if(snow=='*'||snow=='/'||snow=='%') return 7;
if(snow=='P') return 8;
return 0;
}
ll suan(char fu,int a,int b){
if(fu=='+') return a+b;
else if(fu=='-') return a-b;
else if(fu=='*') return a*b;
else if(fu=='/'){
if(b==0) {
bad=1;
return -404;
}
return a/b;
}
else if(fu=='%'){
if(b==0) {
bad=1;
return -404;
}
return a%b;
}
else if(fu=='&') return (a&b);
else if(fu=='^') return (a^b);
else if(fu=='|') return (a|b);
else if(fu=='A') return (a&&b);
else if(fu=='O') return (a||b);
else if(fu=='P') return powl(a,b);
return -404;
}
/*
A=and=&&
O=or=||
P=pow=**
N= != (未做)
Y= == (未做)
*/
string news(string a){
string ans="";
string now="";
char last=' ';
for(char it:a){
if(it==' ') continue;
if(it==last&&it=='&') ans.back()='A';
else if(it==last&&it=='|') ans.back()='O';
else if(it==last&&it=='*') ans.back()='P';
else if(is_fu(it)||it=='('||it==')'){
int in_list=cv[now];
if(in_list==0||in_list==2){
ans+=now;
}else if(in_list==1){
ans+=to_string(int_list[now]);
}
now.clear();
ans+=it;
}
else{
now+=it;
}
last=it;
}
int in_list=cv[now];
if(in_list==0||in_list==2){
ans+=now;
}else if(in_list==1){
ans+=to_string(int_list[now]);
}
return ans;
}
bool can_math(string s){
s=news(s);
for(auto it:s){
if((it>='0'&&it<='9')||is_fu(it)||it==' '||it=='('||it==')') continue;
return 0;
}
return 1;
}
ll MNB(string in){
vector<ll> math;
vector<char> fu;
string now="";
bool cheng=0;
ll kuo=0;
in=news(in);
for(int ii=0;ii<in.size();ii++){
char it=' ';
if(cheng){
ii--;
cheng=0;
it='*';
}
else it=in[ii];
if(bad) break;
if(it==' ') continue;
bool l_k=0;
if(it==')'){
kuo++;
if(ii!=in.size()-1){
if(!is_fu(in[ii+1])){
cheng=1;
}
}
}
if(it=='('){
l_k=1;
if(now.size()){
it='*';
}
}
if((is_fu(it))||it==')'){
if(now.empty()&&is_fu(it)){
if(it=='-'){
now+='-';
continue;
}
bad=3;
return -404;
}
ll sb=0,sb2=1;
string now_2=now;
transform(now_2.begin(), now_2.end(), now_2.begin(), ::tolower);
if(now=="true") sb=1;
else if(now=="false") sb=0;
else sb=stol(now);
now.clear();
while(fu.size()&&(best(fu.back())>=best(it)||fu.back()=='(')){
if(fu.back()=='('){
if(kuo==0) break;
kuo--;
fu.pop_back();
continue;
}
sb=suan(fu.back(),math.back(),sb);
if(bad) break;
fu.pop_back();
math.pop_back();
}
if(it==')'){
now=to_string(sb);
}
else{
math.push_back(sb);
fu.push_back(it);
}
}
else if(it!='('){
now+=it;
}
if(l_k){
fu.push_back('(');
}
}
if(bad){
return -404;
}
// if(now.empty()){
// bad=3;
// return -404;
// }
ll sb=0;
string now_2=now;
transform(now_2.begin(), now_2.end(), now_2.begin(), ::tolower);
if(now=="true") sb=1;
else if(now=="false") sb=0;
else sb=stol(now);
now.clear();
while(fu.size()){
if(fu.back()=='('){
fu.pop_back();
continue;
}
sb=suan(fu.back(),math.back(),sb);
if(bad) break;
fu.pop_back();
math.pop_back();
}
return sb;
}
void math_out(string in){
ll ans=MNB(in);
if(bad==1){
color("MathError:除数错误",4);
bad=0;
} else if(bad==3){
color("MathError:数字缺失",4);
bad=0;
}
else cout<<ans;
// cout<<endl;
return ;
}
//----------------------计算区底----------------------
//----------------------STRING类型辨别区----------------------
bool is_string(string a){
int many=0,much=0;
string bl="";
for(auto it:a){
if(it==' ') continue;
if(it=='+'){
if(bl.size()){
}
continue;
}
if(it=='\"'){
if(much%2==1) return 0;
many++;
}
else if(it=='\''){
if(many%2==1) return 0;
much++;
}
else if(many%2==0&&much%2==0){
bl+=it;
}
}
if(much%2==1||many%2==1||(much==0&&many==0)) return 0;
return 1;
}
//----------------------STRING类型辨别区底----------------------
//----------------------STRING类型加工区----------------------
string new_string(string a){
int many=0;
string now="",ans="",name="";
vector<string> str;
for(char it:a){
if(it=='\"'||it=='\''){
many++;
}else if(many%2==1){
now+=it;
}
else if(it==' ') continue;
else if(it=='+'){
if(now.empty()){
bad=5;
return "error";
}
ans+=now;
now.clear();
}else{
name+=it;
}
}
if(now.empty()){
bad=5;
return "error";
}
ans+=now;
ans='\"'+ans+'\"';
return ans;
}
//----------------------STRING类型加法区底----------------------
//----------------------输入区----------------------
void inside(string in){
string name="",want="";
int sp=in.find("=",0);
for(int i=0;i<sp;i++){
name+=in[i];
}
for(int i=sp+1;i<in.size();i++){
want+=in[i];
}
if(is_string(want)){
string put="";
for(int i=0;i<want.size();i++){
// if(want[i]=='\"'||want[i]=='\'') continue;
put+=want[i];
}
put=new_string(put);
put=turn_char(put);
string_list[name]=put;
int_list[name]=0;
cv[name]=2;
}
else if(can_math(news(want))){
int_list[name]=MNB(want);
string_list[name].clear();
cv[name]=1;
}else{
color("InputError:未知类型\n",4);
}
return ;
}
//----------------------输入区底----------------------
//----------------------输出区----------------------
void outside(string name){
string isd="";
for(int i=8;i<=name.size()-2;i++){
isd+=name[i];
}
string out="";
for(auto it:isd){
if(it==','){
if(can_math(out)){
math_out(out);
}
else if(is_string(out)){
string ost_="";
for(int i=1;i<out.size()-1;i++) ost_+=out[i];
ost_=turn_char(ost_);
cout<<ost_;
}
else if(cv[out]){
if(cv[out]==1) cout<<int_list[out];
else cout<<string_list[out];
}
else{
color("OutError:不存在此变量。",4);
cout<<endl;
return ;
}out.clear();
cout<<' ';
}
else{
out+=it;
}
}
if(can_math(out)){
math_out(out);
}
else if(is_string(out)){
string ost_="";
for(int i=1;i<out.size()-1;i++) ost_+=out[i];
ost_=turn_char(ost_);
cout<<ost_;
}
else if(cv[out]){
if(cv[out]==1) cout<<int_list[out];
else cout<<string_list[out];
}
else{
color("OutError:不存在此变量。",4);
cout<<endl;
return ;
}
cout<<'\n';
return ;
}
//----------------------输出区底----------------------
//----------------------退出区----------------------
void bye(){
int a=rand()%2;
if(a==0) cout<<"Goodbye!";
else if(a==1) cout<<"See you again!";
run=0;
return ;
}
//----------------------退出区底----------------------
//----------------------长运行专属选择区----------------------
void choose_string(string in){
if(in=="end") bye();
else if(find(in,"outside(")==0&&find(in,")")==in.size()-1) outside(in);
else if(find(in,"=")!=-1) inside(in);
else if(can_math(in)&&in.size()){
math_out(news(in));
cout<<endl;
}
else if(in=="game") choose_game();
else color("InputError:未知指令",4);
return ;
}
//----------------------长运行专属选择区底----------------------
//----------------------长运行区----------------------
void long_running(){
for(string it:running_things){
choose_string(it);
}
running_things.clear();
return ;
}
//----------------------长运行区----------------------
//----------------------转运行方式区----------------------
void runtype(string in){
string turn="";
for(int i=8;i<in.size()-1;i++){
turn+=in[i];
}
if(turn=="short"){
if(running_things.size()){
cout<<"检测到长运行模式下的代码未执行,是否执行?(true/false)";
string get="";
cin>>get;
if(get=="true") long_running();
else running_things.clear();
getline(cin,get);
}
run_type=0;
}
else if(turn=="long"){
run_type=1;
}else{
color("TypeError:未知指令",4);
}
return ;
}
//----------------------转运行方式区低----------------------
//----------------------选择区----------------------
void choose(string in){
if(in=="end") bye();
else if(find(in,"runtype(")==0&&find(in,")")==in.size()-1) runtype(in);
else if(in=="run"&&run_type==1) long_running();
else if(run_type){
running_things.push_back(in);
}
else if(find(in,"outside(")==0&&find(in,")")==in.size()-1) outside(in);
else if(find(in,"=")!=-1) inside(in);
else if(can_math(in)&&in.size()){
math_out(news(in));
cout<<endl;
}
else if(in=="game") choose_game();
else color("InputError:未知指令\n",4);
return ;
}
//----------------------选择区底----------------------
int main(){
color("",0);
cout<<"--------------------------------欢迎使用大鹅通--------------------------------\n\n";
while(run){
cout<<">>>";
string in="";
getline(cin,in);
choose(in);
}
return 0;
}
写好久啦
如果要引用某一段的话@我或者跟我私信说一声就好啦
其余我一律当作抄袭哦~(会找AC君的)
使用说明:
①直接输入算式:10+5*6 (输出:40)
②给变量赋值:a=10+5*6 (无输出,a=40) 或者 a="happy\nme too" (无输出,a="happy\nme too",转义字符生效)
③输出变量:outside(a+10) (输出a+10的值,前提是已给a赋值)
④玩游戏:game (开启游戏界面)
⑤使用outside输入算式: outside(10+5*6) (输出40)
注意:尽量用最新版C++,不然会报错
下载地址:https://www.acgo.cn/discuss/study/25401(黄老师干货无敌!)
就到这里了,大家自己玩吧~
如果需要实时更新的话可以评论“球更新”,每次更新我会通知的哦
全部评论 30
24行报错了
2025-08-07 来自 浙江
1这边建议下载C++最新版~
2025-08-07 来自 浙江
0https://www.acgo.cn/discuss/study/25401
2025-08-07 来自 浙江
02025-08-07 来自 浙江
0
球更新
2025-08-06 来自 福建
1已更新,修了计算区的bug
2025-08-07 来自 浙江
0
个人反馈:
- output(输出)感觉比outside(外面)更好,建议使用Ctrl+F替换
- 添加幂运算符
- GAME太少了,可以加点迷宫、贪吃蛇之类的
- 说明建议写在程序内,如加入help指令,该指令会输出各种指令及其用法
不过能编出写运算式就给结果的程序已经很厉害了!
2025-08-06 来自 浙江
1幂是有的,由于跟异或冲突了,所以写的**(python那种)
2025-08-06 来自 浙江
0原来如此
2025-08-06 来自 浙江
0这得说明一下吧
2025-08-06 来自 浙江
0
我帮你加个帮助功能吧
就是提醒有什么功能
2025-08-06 来自 浙江
1感谢大佬欸
2025-08-06 来自 浙江
0原本要沈桢写的
2025-08-06 来自 浙江
0他不想写
2025-08-06 来自 浙江
0
主播主播,第六十五行少了个分号!但是好玩!
2025-08-06 来自 广东
1收到收到~在改啦
2025-08-06 来自 浙江
1更新啦更新啦
2025-08-06 来自 浙江
1好耶
2025-08-06 来自 广东
1
ddd
2025-08-06 来自 浙江
1ddd
2025-08-06 来自 浙江
1
2025-08-05 来自 浙江
1谁让你看了
2025-08-05 来自 浙江
0?
2025-08-05 来自 广东
0我这里腐朽会死的 但是可以打CF)
2025-08-05 来自 广东
0
怎么没人点赞啊
2025-08-05 来自 浙江
1糟糕透了
2025-08-05 来自 浙江
0点了
2025-08-05 来自 广东
0感谢啊啊啊啊啊啊
2025-08-05 来自 浙江
0
@复仇者_帅童换位置了,换了一个帖(他不更新)
2025-08-04 来自 浙江
1行
2025-08-04 来自 浙江
1想给这玩意儿做个循环,求大佬指条明路
2025-08-04 来自 浙江
0什么循环
2025-08-04 来自 浙江
0
d
2025-08-15 来自 浙江
0d
2025-08-15 来自 浙江
0d
2025-08-15 来自 浙江
0ddd
2025-08-09 来自 浙江
0别催了,在加
2025-08-09 来自 浙江
0不行了,犯懒了,摆烂几天
2025-08-09 来自 浙江
0
d
2025-08-06 来自 浙江
0d
2025-08-06 来自 浙江
0d
2025-08-06 来自 浙江
0d
2025-08-06 来自 浙江
0d
2025-08-06 来自 浙江
0ddd
2025-08-05 来自 浙江
0d
2025-08-05 来自 浙江
0
有帮助,赞一个