小游戏+工具
2026-07-06 20:59:00
发布于:浙江
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<windows.h>
using namespace std;
typedef long long ll;
const int M=105;
int n,i,j,k,x,y,p,q,s,t,r,m,op,sc,z,sleep,h;
ll a,b,c,d;
char ch,str[M];
bool f;
void g1(){//猜数字1-100
srand((unsigned)time(NULL));
x=rand()%100+1;
cout<<"Game1:猜1~100数字\n";
while(1){
cin>>y;
if(y>x)cout<<"大了\n";
else if(y<x)cout<<"小了\n";
else {cout<<"猜对!\n";break;}
}
}
void g2(){//骰子点数
srand((unsigned)time(NULL));
cout<<"Game2:掷两颗骰子\n";
x=rand()%6+1;y=rand()%6+1;
cout<<"点数:"<<x<<" "<<y<<" 和:"<<x+y<<"\n";
}
void g3(){//奇偶判断
cout<<"Game3:输入数字判奇偶\n";
cin>>x;
if(x%2)cout<<"奇数\n";
else cout<<"偶数\n";
}
void g4(){//乘法口算
srand((unsigned)time(NULL));
x=rand()%12+1;y=rand()%12+1;
cout<<"Game4:"<<x<<"×"<<y<<"=?\n";
cin>>z;
if(z==x*y)cout<<"正确\n";
else cout<<"错,答案"<<x*y<<"\n";
}
void g5(){//倒计时3秒
cout<<"Game5:倒计时3秒\n";
for(i=3;i>0;i--){cout<<i<<endl;}
cout<<"结束\n";
}
void g6(){//字母大小写转换
cout<<"Game6:输入大写转小写\n";
cin>>ch;
cout<<char(ch+32)<<"\n";
}
void g7(){//求和1~n
cout<<"Game7:求1到n和\n";
cin>>n;
s=0;for(i=1;i<=n;i++)s+=i;
cout<<"和:"<<s<<"\n";
}
void g8(){//质数判断
cout<<"Game8:质数判断\n";
cin>>x;f=1;
for(i=2;i*i<=x;i++)if(x%i==0){f=0;break;}
if(f&&x>1)cout<<"质数\n";else cout<<"非质数\n";
}
void g9(){//石头剪刀布
srand((unsigned)time(NULL));
cout<<"Game9:0石头1剪刀2布\n";
cin>>x;y=rand()%3;
cout<<"电脑:"<<y<<"\n";
if(x==y)cout<<"平局\n";
else if((x==0&&y==1)||(x==1&&y==2)||(x==2&&y==0))cout<<"你赢\n";
else cout<<"你输\n";
}
void g10(){//倒序输出数字
cout<<"Game10:输入n倒序输出1~n\n";
cin>>n;
for(i=n;i>=1;i--)cout<<i<<" ";cout<<"\n";
}
//11-20
void g11(){cout<<"Game11:简易计算器\n";cin>>a>>ch>>b;if(ch=='+')cout<<a+b;if(ch=='-')cout<<a-b;if(ch=='*')cout<<a*b;if(ch=='/')cout<<a/b;cout<<"\n";}
void g12(){srand(time(0));cout<<"Game12:抽1-50幸运数\n";cout<<rand()%50+1<<"\n";}
void g13(){cout<<"Game13:统计数字位数\n";cin>>x;s=0;while(x>0){s++;x/=10;}cout<<"位数:"<<s<<"\n";}
void g14(){cout<<"Game14:交换两数\n";cin>>x>>y;swap(x,y);cout<<x<<" "<<y<<"\n";}
void g15(){cout<<"Game15:正方形星图\n";cin>>n;for(i=1;i<=n;i++){for(j=1;j<=n;j++)cout<<"*";cout<<"\n";}}
void g16(){cout<<"Game16:三角形星图\n";cin>>n;for(i=1;i<=n;i++){for(j=1;j<=i;j++)cout<<"*";cout<<"\n";}}
void g17(){cout<<"Game17:水仙花数判断\n";cin>>x;a=x;s=0;while(a>0){k=a%10;s+=k*k*k;a/=10;}if(s==x)cout<<"是水仙花数\n";else cout<<"不是\n";}
void g18(){cout<<"Game18:最大公约数\n";cin>>x>>y;while(y){r=x%y;x=y;y=r;}cout<<"gcd:"<<x<<"\n";}
void g19(){cout<<"Game19:斐波那契第n项\n";cin>>n;a=1,b=1;if(n<=2)cout<<1;else for(i=3;i<=n;i++){c=a+b;a=b;b=c;}cout<<b<<"\n";}
void g20(){cout<<"Game20:字符长度统计\n";cin>>str;cout<<"长度:"<<strlen(str)<<"\n";}
//21-30
void g21(){srand(time(0));cout<<"Game21:抽卡牌1-13\n";cout<<rand()%13+1<<"\n";}
void g22(){cout<<"Game22:平方计算\n";cin>>x;cout<<x*x<<"\n";}
void g23(){cout<<"Game23:立方计算\n";cin>>x;cout<<x*x*x<<"\n";}
void g24(){cout<<"Game24:判断回文数字\n";cin>>x;a=x;s=0;while(a>0){s=s*10+a%10;a/=10;}if(s==x)cout<<"回文\n";else cout<<"非回文\n";}
void g25(){cout<<"Game25:输出九九乘法表\n";for(i=1;i<=9;i++){for(j=1;j<=i;j++)cout<<j<<"×"<<i<<"="<<i*j<<" ";cout<<"\n";}}
void g26(){cout<<"Game26:输入数字转二进制\n";cin>>x;while(x>0){cout<<x%2;x/=2;}cout<<"\n";}
void g27(){cout<<"Game27:区间偶数和\n";cin>>x>>y;s=0;for(i=x;i<=y;i++)if(i%2==0)s+=i;cout<<s<<"\n";}
void g28(){cout<<"Game28:区间奇数和\n";cin>>x>>y;s=0;for(i=x;i<=y;i++)if(i%2)s+=i;cout<<s<<"\n";}
void g29(){srand(time(0));cout<<"Game29:随机0/1硬币\n";cout<<rand()%2<<"\n";}
void g30(){cout<<"Game30:简单密码验证\n";cin>>str;if(strcmp(str,"123456")==0)cout<<"密码正确\n";else cout<<"错误\n";}
//31-40
void g31(){cout<<"Game31:求圆面积\n";cin>>x;printf("%.2lf\n",3.1415*x*x);}
void g32(){cout<<"Game32:矩形周长\n";cin>>x>>y;cout<<2*(x+y)<<"\n";}
void g33(){cout<<"Game33:矩形面积\n";cin>>x>>y;cout<<x*y<<"\n";}
void g34(){cout<<"Game34:统计字符串大写字母\n";cin>>str;s=0;for(i=0;str[i];i++)if(str[i]>='A'&&str[i]<='Z')s++;cout<<s<<"\n";}
void g35(){cout<<"Game35:统计字符串小写字母\n";cin>>str;s=0;for(i=0;str[i];i++)if(str[i]>='a'&&str[i]<='z')s++;cout<<s<<"\n";}
void g36(){srand(time(0));cout<<"Game36:随机10-99两位数\n";cout<<rand()%90+10<<"\n";}
void g37(){cout<<"Game37:数字绝对值\n";cin>>x;cout<<abs(x)<<"\n";}
void g38(){cout<<"Game38:阶乘计算\n";cin>>n;s=1;for(i=1;i<=n;i++)s*=i;cout<<s<<"\n";}
void g39(){cout<<"Game39:最小值查找\n";cin>>x>>y>>z;s=x;if(y<s)s=y;if(z<s)s=z;cout<<"最小:"<<s<<"\n";}
void g40(){cout<<"Game40:最大值查找\n";cin>>x>>y>>z;s=x;if(y>s)s=y;if(z>s)s=z;cout<<"最大:"<<s<<"\n";}
//41-50
void g41(){cout<<"Game41:输入字符转ASCII\n";cin>>ch;cout<<(int)ch<<"\n";}
void g42(){cout<<"Game42:ASCII转字符\n";cin>>x;cout<<(char)x<<"\n";}
void g43(){cout<<"Game43:10以内加法闯关3题\n";sc=0;srand(time(0));for(i=1;i<=3;i++){x=rand()%10;y=rand()%10;cout<<x<<"+"<<y<<"=";cin>>z;if(z==x+y)sc++;}cout<<"得分:"<<sc<<"/3\n";}
void g44(){cout<<"Game44:10以内减法闯关3题\n";sc=0;srand(time(0));for(i=1;i<=3;i++){x=rand()%10;y=rand()%10;cout<<x<<"-"<<y<<"=";cin>>z;if(z==x-y)sc++;}cout<<"得分:"<<sc<<"/3\n";}
void g45(){cout<<"Game45:菱形星图\n";cin>>n;for(i=1;i<=n;i++){for(j=1;j<=n-i;j++)cout<<" ";for(j=1;j<=2*i-1;j++)cout<<"*";cout<<"\n";}for(i=n-1;i>=1;i--){for(j=1;j<=n-i;j++)cout<<" ";for(j=1;j<=2*i-1;j++)cout<<"*";cout<<"\n";}}
void g46(){cout<<"Game46:判断闰年\n";cin>>x;if((x%4==0&&x%100!=0)||x%400==0)cout<<"闰年\n";else cout<<"平年\n";}
void g47(){cout<<"Game47:分离数字各位\n";cin>>x;while(x>0){cout<<x%10<<" ";x/=10;}cout<<"\n";}
void g48(){cout<<"Game48:字符串反转\n";cin>>str;m=strlen(str);for(i=m-1;i>=0;i--)cout<<str[i];cout<<"\n";}
void g49(){srand(time(0));cout<<"Game49:随机颜色编号0-6\n";cout<<rand()%7<<"\n";}
void g50(){cout<<"Game50:三角形三边判断\n";cin>>x>>y>>z;if(x+y>z&&x+z>y&&y+z>x)cout<<"可构成三角形\n";else cout<<"不可\n";}
//51-60
void g51(){cout<<"Game51:求和平方和1~n\n";cin>>n;s=0;for(i=1;i<=n;i++)s+=i*i;cout<<s<<"\n";}
void g52(){cout<<"Game52:立方和1~n\n";cin>>n;s=0;for(i=1;i<=n;i++)s+=i*i*i;cout<<s<<"\n";}
void g53(){srand(time(0));cout<<"Game53:四骰子总和\n";x=rand()%6+1;y=rand()%6+1;p=rand()%6+1;q=rand()%6+1;cout<<"总点数:"<<x+y+p+q<<"\n";}
void g54(){cout<<"Game54:数字取模\n";cin>>x>>y;cout<<x%y<<"\n";}
void g55(){cout<<"Game55:输出100以内7倍数\n";for(i=7;i<=100;i+=7)cout<<i<<" ";cout<<"\n";}
void g56(){cout<<"Game56:输出100以内9倍数\n";for(i=9;i<=100;i+=9)cout<<i<<" ";cout<<"\n";}
void g57(){cout<<"Game57:字符替换a→b\n";cin>>str;for(i=0;str[i];i++)if(str[i]=='a')str[i]='b';cout<<str<<"\n";}
void g58(){cout<<"Game58:计算两点距离\n";cin>>x>>y>>p>>q;printf("%.2lf\n",sqrt((x-p)*(x-p)+(y-q)*(y-q)));}
void g59(){cout<<"Game59:简易投票统计0/1\n";cin>>n;s=0;for(i=1;i<=n;i++){cin>>x;if(x==1)s++;}cout<<"1票数:"<<s<<" 0票数:"<<n-s<<"\n";}
void g60(){cout<<"Game60:素数区间统计\n";cin>>x>>y;s=0;for(i=x;i<=y;i++){f=1;for(j=2;j*j<=i;j++)if(i%j==0){f=0;break;}if(f&&i>1)s++;}cout<<"区间素数个数:"<<s<<"\n";}
//61-70
void g61(){cout<<"Game61:倒序九九乘法表\n";for(i=9;i>=1;i--){for(j=1;j<=i;j++)cout<<j<<"×"<<i<<"="<<i*j<<" ";cout<<"\n";}}
void g62(){cout<<"Game62:十六进制转十进制\n";cin>>str;ll res=0;for(i=0;str[i];i++){res*=16;if(str[i]>='0'&&str[i]<='9')res+=str[i]-'0';else res+=str[i]-'A'+10;}cout<<res<<"\n";}
void g63(){srand(time(0));cout<<"Game63:随机奖励分1-100\n";cout<<rand()%100+1<<"\n";}
void g64(){cout<<"Game64:平均值计算\n";cin>>n;s=0;for(i=1;i<=n;i++){cin>>x;s+=x;}printf("%.2lf\n",1.0*s/n);}
void g65(){cout<<"Game65:空格填充字符串\n";cin>>str;for(i=0;i<10-strlen(str);i++)cout<<" ";cout<<str<<"\n";}
void g66(){cout<<"Game66:3的倍数判断\n";cin>>x;if(x%3==0)cout<<"是3倍数\n";else cout<<"不是\n";}
void g67(){cout<<"Game67:5的倍数判断\n";cin>>x;if(x%5==0)cout<<"是5倍数\n";else cout<<"不是\n";}
void g68(){cout<<"Game68:随机四则运算答题\n";srand(time(0));int op=rand()%4;x=rand()%20;y=rand()%20;ll ans;if(op==0){cout<<x<<"+"<<y<<"=";ans=x+y;}if(op==1){cout<<x<<"-"<<y<<"=";ans=x-y;}if(op==2){cout<<x<<"×"<<y<<"=";ans=x*y;}if(op==3){cout<<x<<"/"<<y<<"=";ans=x/y;}cin>>z;if(z==ans)cout<<"正确\n";else cout<<"错\n";}
void g69(){cout<<"Game69:直角三角形星图右对齐\n";cin>>n;for(i=1;i<=n;i++){for(j=1;j<=n-i;j++)cout<<" ";for(j=1;j<=i;j++)cout<<"*";cout<<"\n";}}
void g70(){cout<<"Game70:字符串数字提取求和\n";cin>>str;s=0;for(i=0;str[i];i++)if(str[i]>='0'&&str[i]<='9')s+=str[i]-'0';cout<<"数字总和:"<<s<<"\n";}
//71-80
void g71(){cout<<"Game71:2的n次方\n";cin>>n;ll r=1;for(i=1;i<=n;i++)r*=2;cout<<r<<"\n";}
void g72(){cout<<"Game72:3的n次方\n";cin>>n;ll r=1;for(i=1;i<=n;i++)r*=3;cout<<r<<"\n";}
void g73(){srand(time(0));cout<<"Game73:抽奖1-1000\n";cout<<rand()%1000+1<<"\n";}
void g74(){cout<<"Game74:月份天数判断\n";cin>>x;if(x==2)cout<<"28/29天\n";else if(x==4||x==6||x==9||x==11)cout<<"30天\n";else cout<<"31天\n";}
void g75(){cout<<"Game75:大小写互换字符串\n";cin>>str;for(i=0;str[i];i++){if(str[i]>='A'&&str[i]<='Z')str[i]+=32;else if(str[i]>='a'&&str[i]<='z')str[i]-=32;}cout<<str<<"\n";}
void g76(){cout<<"Game76:数组最大值最小值差\n";cin>>n;int mx=-1e9,mn=1e9;for(i=1;i<=n;i++){cin>>x;if(x>mx)mx=x;if(x<mn)mn=x;}cout<<"差值:"<<mx-mn<<"\n";}
void g77(){cout<<"Game77:判断完全平方数\n";cin>>x;k=sqrt(x);if(k*k==x)cout<<"完全平方\n";else cout<<"不是\n";}
void g78(){cout<<"Game78:简易加密字符+3\n";cin>>ch;cout<<char(ch+3)<<"\n";}
void g79(){cout<<"Game79:简易解密字符-3\n";cin>>ch;cout<<char(ch-3)<<"\n";}
void g80(){cout<<"Game80:1~n所有质数输出\n";cin>>n;for(i=2;i<=n;i++){f=1;for(j=2;j*j<=i;j++)if(i%j==0){f=0;break;}if(f)cout<<i<<" ";}cout<<"\n";}
//81-90
void g81(){cout<<"Game81:加权平均分\n";cin>>x>>y>>p>>q;printf("%.2lf\n",(1.0*x*p+y*q)/(p+q));}
void g82(){srand(time(0));cout<<"Game82:三局两胜石头剪刀布\n";sc=0;for(i=1;i<=3;i++){cout<<"第"<<i<<"局0石头1剪刀2布\n";cin>>x;y=rand()%3;cout<<"电脑"<<y<<"\n";if((x==0&&y==1)||(x==1&&y==2)||(x==2&&y==0))sc++;}if(sc>=2)cout<<"总胜利\n";else cout<<"总失败\n";}
void g83(){cout<<"Game83:空心正方形\n";cin>>n;for(i=1;i<=n;i++){for(j=1;j<=n;j++)if(i==1||i==n||j==1||j==n)cout<<"*";else cout<<" ";cout<<"\n";}}
void g84(){cout<<"Game84:数字位数逆序拼接\n";cin>>x;s=0;while(x>0){s=s*10+x%10;x/=10;}cout<<s<<"\n";}
void g85(){cout<<"Game85:区间能被4整除和\n";cin>>x>>y;s=0;for(i=x;i<=y;i++)if(i%4==0)s+=i;cout<<s<<"\n";}
void g86(){cout<<"Game86:统计字符串数字个数\n";cin>>str;s=0;for(i=0;str[i];i++)if(str[i]>='0'&&str[i]<='9')s++;cout<<"数字数量:"<<s<<"\n";}
void g87(){cout<<"Game87:计算梯形面积\n";cin>>x>>y>>h;printf("%.2lf\n",(x+y)*h/2.0);}
void g88(){cout<<"Game88:随机1-20乘法答题\n";srand(time(0));x=rand()%20+1;y=rand()%20+1;cout<<x<<"×"<<y<<"=";cin>>z;if(z==x*y)cout<<"满分\n";else cout<<"错误答案"<<x*y<<"\n";}
void g89(){cout<<"Game89:输入n输出n个星号\n";cin>>n;for(i=1;i<=n;i++)cout<<"*";cout<<"\n";}
void g90(){cout<<"Game90:素因数分解\n";cin>>x;cout<<"分解:";for(i=2;i*i<=x;i++)while(x%i==0){cout<<i<<" ";x/=i;}if(x>1)cout<<x;cout<<"\n";}
//91-100
void g91(){cout<<"Game91:10以内混合运算闯关2题\n";sc=0;srand(time(0));for(i=1;i<=2;i++){int t=rand()%3;x=rand()%10;y=rand()%10;if(t==0){cout<<x<<"+"<<y<<"=";cin>>z;if(z==x+y)sc++;}if(t==1){cout<<x<<"-"<<y<<"=";cin>>z;if(z==x-y)sc++;}if(t==2){cout<<x<<"×"<<y<<"=";cin>>z;if(z==x*y)sc++;}}cout<<"得分:"<<sc<<"/2\n";}
void g92(){cout<<"Game92:空心菱形\n";cin>>n;for(i=1;i<=n;i++){for(j=1;j<=n-i;j++)cout<<" ";cout<<"*";for(j=1;j<=2*i-3;j++)cout<<" ";if(i>1)cout<<"*";cout<<"\n";}for(i=n-1;i>=1;i--){for(j=1;j<=n-i;j++)cout<<" ";cout<<"*";for(j=1;j<=2*i-3;j++)cout<<" ";if(i>1)cout<<"*";cout<<"\n";}}
void g93(){cout<<"Game93:输入年份输出生肖(鼠0牛1...猪11)\n";cin>>x;x-=2020;x=(x%12+12)%12;cout<<"生肖编号:"<<x<<"\n";}
void g94(){cout<<"Game94:字符串去空格\n";cin.get();cin.getline(str,M);int p=0;for(i=0;str[i];i++)if(str[i]!=' ')str[p++]=str[i];str[p]='\0';cout<<str<<"\n";}
void g95(){cout<<"Game95:立方体体积\n";cin>>x;cout<<x*x*x<<"\n";}
void g96(){cout<<"Game96:立方体表面积\n";cin>>x;cout<<6*x*x<<"\n";}
void g97(){srand(time(0));cout<<"Game97:双色球随机6个1-33不重复\n";int vis[34]={0};for(i=1;i<=6;i++){while(1){k=rand()%33+1;if(!vis[k]){vis[k]=1;cout<<k<<" ";break;}}};cout<<"\n";}
void g98(){cout<<"Game98:最大连续数字和\n";cin>>n;int mx=-1e9,cur=0;for(i=1;i<=n;i++){cin>>x;cur=max(x,cur+x);mx=max(mx,cur);}cout<<"最大连续和:"<<mx<<"\n";}
void g99(){cout<<"Game99:输入数字转八进制\n";cin>>x;char buf[M];itoa(x,buf,8);cout<<buf<<"\n";}
void g100(){cout<<"Game100:终极综合闯关5题\n";sc=0;srand(time(0));for(int q=1;q<=5;q++){int t=rand()%4;x=rand()%15;y=rand()%15;ll ans;if(t==0){cout<<x<<"+"<<y<<"=";ans=x+y;}if(t==1){cout<<x<<"-"<<y<<"=";ans=x-y;}if(t==2){cout<<x<<"×"<<y<<"=";ans=x*y;}if(t==3){cout<<x<<"/"<<y<<"=";ans=x/y;}cin>>z;if(z==ans)sc++;}cout<<"闯关得分:"<<sc<<"/5\n";}
void run(int id){
switch(id){
case 1:g1();break;case 2:g2();break;case 3:g3();break;case 4:g4();break;case 5:g5();break;
case 6:g6();break;case 7:g7();break;case 8:g8();break;case 9:g9();break;case 10:g10();break;
case 11:g11();break;case 12:g12();break;case 13:g13();break;case 14:g14();break;case 15:g15();break;
case 16:g16();break;case 17:g17();break;case 18:g18();break;case 19:g19();break;case 20:g20();break;
case 21:g21();break;case 22:g22();break;case 23:g23();break;case 24:g24();break;case 25:g25();break;
case 26:g26();break;case 27:g27();break;case 28:g28();break;case 29:g29();break;case 30:g30();break;
case 31:g31();break;case 32:g32();break;case 33:g33();break;case 34:g34();break;case 35:g35();break;
case 36:g36();break;case 37:g37();break;case 38:g38();break;case 39:g39();break;case 40:g40();break;
case 41:g41();break;case 42:g42();break;case 43:g43();break;case 44:g44();break;case 45:g45();break;
case 46:g46();break;case 47:g47();break;case 48:g48();break;case 49:g49();break;case 50:g50();break;
case 51:g51();break;case 52:g52();break;case 53:g53();break;case 54:g54();break;case 55:g55();break;
case 56:g56();break;case 57:g57();break;case 58:g58();break;case 59:g59();break;case 60:g60();break;
case 61:g61();break;case 62:g62();break;case 63:g63();break;case 64:g64();break;case 65:g65();break;
case 66:g66();break;case 67:g67();break;case 68:g68();break;case 69:g69();break;case 70:g70();break;
case 71:g71();break;case 72:g72();break;case 73:g73();break;case 74:g74();break;case 75:g75();break;
case 76:g76();break;case 77:g77();break;case 78:g78();break;case 79:g79();break;case 80:g80();break;
case 81:g81();break;case 82:g82();break;case 83:g83();break;case 84:g84();break;case 85:g85();break;
case 86:g86();break;case 87:g87();break;case 88:g88();break;case 89:g89();break;case 90:g90();break;
case 91:g91();break;case 92:g92();break;case 93:g93();break;case 94:g94();break;case 95:g95();break;
case 96:g96();break;case 97:g97();break;case 98:g98();break;case 99:g99();break;case 100:g100();break;
default:cout<<"无此游戏\n";
}
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
while(1){
cout<<"=====100合1迷你游戏合集=====\n";
cout<<"输入1~100选择游戏,输入0退出\n";
cin>>op;
if(op==0){cout<<"退出游戏\n";break;}
run(op);
cout<<"按回车返回菜单\n";getchar();getchar();system("cls");
}
return 0;
}
这里空空如也













有帮助,赞一个