0
已解决
王煜辰
中级光能
中级光能
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<random>
#include<sstream>
#include<time.h>
using namespace std;
void gotoxy(int,int);
void full_screen();
void hidegd();
int setcolor(int,int,int);
void hideCursor();
void vertical(string,string,int,char);
void PLUSvt(int ,int,long long,long long);
void spaceprint(string,bool,char);
void chushihua();A
void chushihua()
{
system("cls");
gotoxy(0,0);
}
void font(int x)
{
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize=sizeof(cfi);
cfi.nFont=0;
cfi.dwFontSize.X=0;
cfi.dwFontSize.Y=x;
cfi.FontFamily=FF_DONTCARE;
cfi.FontWeight=FW_NORMAL;
std::wcscpy(cfi.FaceName, L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
}
void full_screen()
{
HWND hwnd=GetForegroundWindow();
int cx=GetSystemMetrics(SM_CXSCREEN);
int cy=GetSystemMetrics(SM_CYSCREEN);
LONG l_WinStyle=GetWindowLong(hwnd,GWL_STYLE);
SetWindowLong(hwnd,GWL_STYLE,(l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);
SetWindowPos(hwnd,HWND_TOP,0,0,cx,cy,0);
}
void gotoxy(int x,int y)
{
COORD c;
c.X=x;
c.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
template<typename T>
void ColorCout(T t, const int ForeColor = 7, const int BackColor = 0)
{
// 0 = 黑色 1 = 蓝色 2 = 绿色 3 = 浅绿色 4 = 红色 5 = 紫色 6 = 黄色 7 = 白色
// 8 = 灰色 9 = 淡蓝色 10 = 淡绿色 11 = 淡浅绿色 12 = 淡红色 13 = 淡紫色 14 = 淡黄色 15 = 亮白色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),ForeColor+BackColor*0x10);
cout<<t;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0+15*0x10);
}
void hideCursor()
{
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursorInfo);
cursorInfo.bVisible=FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursorInfo);
}
string qqqdl(string s)
{
while(s[0]=='0'&&s.size()>1)s.erase(0,1);
return s;
}
void PLUSvt(int a,int b,long long jfbl,long long dfbl)
{
cout<<"己方兵力:"<<jfbl;
Sleep(1000);
cout<<endl;
cout<<"对方兵力:"<<dfbl;
Sleep(1000);
cout<<"是否开战"
system("cls");
cout<<"请按任意键继续";
getch();
}
void MINUSvt(string a,string b,int jinzhi)
{
bool fushu=0;
chushihua();
a=qqqdl(a);
b=qqqdl(b);
string ans="";
string s=" ";
int x=max(a.size(),b.size());
if(b.size()>a.size()||b.size()==a.size()&&b>a)fushu=1;
else swap(a,b);
int temp=b.size()-a.size();
for(int i=1; i<=temp; i++)a=' '+a;
spaceprint(b,1,'-');
spaceprint(a,0,'-');
for(int i=1; i<=x*2+3; i++)cout<<"-";
int carry=0;
for(; x!=0;)
{
gotoxy(0,7);
cout<<"请按任意键继续";
gotoxy(0,4);
if(carry!=0)cout<<"被借位,借走"<<carry<<'\n';
else cout<<"不被借位 \n";
if(a[x-1]==' ')a[x-1]='0';
int jian1,jian2;
if(isupper(a[x-1]))jian1=a[x-1]-'A'+10;
else if(islower(a[x-1]))jian1=a[x-1]-'a'+10;
else jian1=a[x-1]-'0';
if(isupper(b[x-1]))jian2=b[x-1]-'A'+10;
else if(islower(b[x-1]))jian2=b[x-1]-'a'+10;
else jian2=b[x-1]-'0';
int t=jian2-jian1-carry;
cout<<'\n';
cout<<s;
gotoxy(0,6);
if(carry!=0)
{
if(t>=0)
{
cout<<b[x-1]<<"-"<<a[x-1]<<"-"<<carry<<"=";
carry=0;
}
else
{
cout<<b[x-1]<<"-"<<a[x-1]<<"-"<<carry<<"+"<<jinzhi<<"=";
carry=1;
}
}
else
{
if(t>=0)
{
cout<<b[x-1]<<"-"<<a[x-1]<<"=";
carry=0;
}
else
{
cout<<b[x-1]<<"-"<<a[x-1]<<"+"<<jinzhi<<"=";
carry=1;
}
}
if(t<0)
{
t+=jinzhi;
if(t>=10)cout<<char(t%jinzhi-10+'A');
else cout<<t%jinzhi;
}
else
{
if(t>=10)cout<<char(t%jinzhi-10+'A');
else cout<<t%jinzhi;
}
int out=t;
gotoxy(2*x+1,3);
if(out>=10)
{
ColorCout(char(out-10+'A'),6,9);
ans=char(out-10+'A')+ans;
}
else
{
ColorCout(out,6,9);
ans=char(out+'0')+ans;
}
if(carry==1)
{
gotoxy(0,5);
cout<<"需借位,借来"<<jinzhi;
}
else
{
gotoxy(0,5);
cout<<"无需借位 ";
}
getch();
gotoxy(2*x+1,3);
if(out>=10)ColorCout(char(out-10+'A'),0,15);
else ColorCout(out,0,15);
x--;
}
if(fushu)
{
gotoxy(0,7);
cout<<"请按任意键继续";
gotoxy(0,4);
cout<<s;
gotoxy(0,5);
cout<<s;
gotoxy(0,6);
cout<<s;
gotoxy(0,4);
cout<<"是负数"<<'\n';
gotoxy(1,3);
cout<<'-';
getch();
}
system("cls");
gotoxy(0,0);
ans=qqqdl(ans);
cout<<"计算结束!\n";
cout<<"计算结果:"<<(fushu?'-'+ans:ans)<<'\n';
cout<<"请按任意键继续";
getch();
}
char cl(int x)
{
if(x<10)return char(x+'0');
else return char(x-10+'A');
}
void jishuqi(int jinzhi)
{
st:
int b[15];
memset(b,0,sizeof(b));
chushihua();
for(int i=1; i<=jinzhi; i++)cout<<" | | | | | | | | | | | |\n";
cout<<"序号:12 11 10 9 8 7 6 5 4 3 2 1\n";
printf("数值:%d %d %d %d %d %d %d %d %d %d %d %d\n",b[12],b[11],b[10],b[9],b[8],b[7],b[6],b[5],b[4],b[3],b[2],b[1]);
cout<<"命令:\n";
cout<<"按I:加上一个数\n按E:减去一个数\n按A:在某个数位上操作\n按X:退出";
bool firstget=0;
while(1)
{
char c=getch();
if(c=='i'||c=='I')
{
string s;
gotoxy(70,0);
cout<<"请输入一个数:";
gotoxy(65,1);
if(firstget==0)getline(cin,s),firstget=1;
getline(cin,s);
int flag=1;
while(s.size()>12)
{
s.erase(0,1);
flag=0;
}
if(!flag)MessageBox(NULL,"超出范围!(超出后只保留不超出的部分)","错误",MB_OK);
gotoxy(65,1);
cout<<" ";
gotoxy(70,0);
cout<<" ";
gotoxy(65,1);
int t=0;
for(int i=s.size()-1; i>=0; i--)
{
if(isdigit(s[i]))b[++t]+=s[i]-'0';
else if(isupper(s[i]))b[++t]+=s[i]-'A'+10;
else if(islower(s[i]))b[++t]+=s[i]-'a'+10;
if(b[t]>=jinzhi)
{
b[t]-=jinzhi;
if(t+1<=12)b[t+1]++;
else MessageBox(NULL,"超出范围!(超出后只保留不超出的部分)","错误",MB_OK);
}
}
for(int i=12; i>=1; i--)
{
if(b[13-i]>=jinzhi)
{
b[13-i]-=jinzhi;
if(i!=1)b[14-i]++;
else MessageBox(NULL,"超出范围!(超出后只保留不超出的部分)","错误",MB_OK);
}
for(int j=1; j<=jinzhi-1; j++)
{
gotoxy(5*i-1,jinzhi-j);
if(j<=b[13-i])cout<<"[ ]";
else cout<<" | ";
}
}
}
else if(c=='E'||c=='e')
{
string s;
gotoxy(70,0);
cout<<"请输入一个数:";
gotoxy(65,1);
if(firstget==0)getline(cin,s),firstget=1;
getline(cin,s);
int flag=1;
while(s.size()>12)
{
s.erase(0,1);
flag=0;
}
if(!flag)
{
MessageBox(NULL,"数会小于零!(清零)","错误",MB_OK);
goto st;
}
gotoxy(65,1);
cout<<" ";
gotoxy(70,0);
cout<<" ";
gotoxy(65,1);
int t=0;
for(int i=s.size()-1; i>=0; i--)
{
if(isdigit(s[i]))b[++t]-=s[i]-'0';
else if(isupper(s[i]))b[++t]-=s[i]-'A'+10;
else if(islower(s[i]))b[++t]-=s[i]-'a'+10;
if(b[t]<0)
{
b[t]+=jinzhi;
if(t+1<=12)b[t+1]--;
else MessageBox(NULL,"超出范围!(超出后只保留不超出的部分)","错误",MB_OK);
}
}
for(int i=12; i>=1; i--)
{
if(b[13-i]<0)
{
b[13-i]+=jinzhi;
if(i!=1)b[14-i]--;
else
{
MessageBox(NULL,"数会小于零!(清零)","错误",MB_OK);
goto st;
}
}
for(int j=1; j<=jinzhi-1; j++)
{
gotoxy(5*i-1,jinzhi-j);
if(j<=b[13-i])cout<<"[ ]";
else cout<<" | ";
}
}
}
else if(c=='A'||c=='a')
{
Aa:
string s;
gotoxy(70,0);
cout<<"请输入您要操作的数位的序号:";
gotoxy(65,1);
int ttt;
cin>>ttt;
if(ttt>12||ttt<1)
{
MessageBox(NULL,"错误!(请重新输入)","错误",MB_OK);
gotoxy(70,0);
cout<<" ";
gotoxy(65,1);
cout<<" ";
goto Aa;
}
gotoxy(65,1);
cout<<" ";
gotoxy(70,0);
cout<<" ";
gotoxy(70,0);
cout<<"按1加算珠,按2减算珠";
char tmp=getch();
gotoxy(70,0);
cout<<" ";
if(tmp=='1')
{
tmp1cw:
gotoxy(70,0);
cout<<"请输入您要加的算珠数目(小于"<<jinzhi<<"):";
gotoxy(65,1);
int xxx;
cin>>xxx;
gotoxy(70,0);
cout<<" ";
gotoxy(65,1);
cout<<" ";
if(xxx>jinzhi)
{
MessageBox(NULL,"错误!(请重新输入)","错误",MB_OK);
goto tmp1cw;
}
b[ttt]+=xxx;
for(int i=12; i>=1; i--)
{
if(b[13-i]>=jinzhi)
{
b[13-i]-=jinzhi;
if(i!=1)b[14-i]++;
else MessageBox(NULL,"超出范围!(超出后只保留不超出的部分)","错误",MB_OK);
}
for(int j=1; j<=jinzhi-1; j++)
{
gotoxy(5*i-1,jinzhi-j);
if(j<=b[13-i])cout<<"[ ]";
else cout<<" | ";
}
}
}
else if(tmp=='2')
{
tmp2cw:
gotoxy(70,0);
cout<<"请输入您减的算珠数目(小于"<<jinzhi<<"):";
gotoxy(65,1);
int xxx;
cin>>xxx;
if(xxx>jinzhi)
{
MessageBox(NULL,"错误!(请重新输入)","错误",MB_OK);
goto tmp2cw;
}
gotoxy(70,0);
cout<<" ";
gotoxy(65,1);
cout<<" ";
b[ttt]-=xxx;
for(int i=12; i>=1; i--)
{
if(b[13-i]<0)
{
b[13-i]+=jinzhi;
if(i!=1)b[14-i]--;
else
{
MessageBox(NULL,"数会小于零!(清零)","错误",MB_OK);
goto st;
}
}
for(int j=1; j<=jinzhi-1; j++)
{
gotoxy(5*i-1,jinzhi-j);
if(j<=b[13-i])cout<<"[ ]";
else cout<<" | ";
}
}
}
}
else if(c=='x'||c=='X')
{
system("cls");
break;
}
end:
gotoxy(0,jinzhi+1);
printf("数值:%c %c %c %c %c %c %c %c %c %c %c %c\n",cl(b[12]),cl(b[11]),cl(b[10]),cl(b[9]),cl(b[8]),cl(b[7]),cl(b[6]),cl(b[5]),cl(b[4]),cl(b[3]),cl(b[2]),cl(b[1]));
}
}
void spaceprint(string s,bool a,char c)
{
if(a==1)cout<<" ";
else cout<<" "<<c;
for(int i=0; i<s.size(); i++)cout<<" "<<s[i];
cout<<'\n';
return;
}
int main()
{
short state1=GetKeyState(VK_CAPITAL);
short state2=GetKeyState(VK_NUMLOCK);
if(state1&0x1);
else
{
keybd_event(VK_CAPITAL,0,0,0);
keybd_event(VK_CAPITAL,0,2,0);
}
if(state2&0x1);
else
{
keybd_event(VK_NUMLOCK,0,0,0);
keybd_event(VK_NUMLOCK,0,2,0);
}
full_screen();
system("color F0");
hideCursor();
font(36);
while(1)
{
start:
system("cls");
string s="欢迎来到全面战争模拟器!";
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(25);
}
cout<<endl;
Sleep(200);
s="选择国家:按1\n随机国家:按2\n自定义国家:按3\n退出:按4\n";
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(25);
}
char c=getch();
if(c=='1')
{
system("cls");
s="己方国家:中国:按1\n俄罗斯:按2\n美国:按3\n英国:按4\n法国:按5\n";
string z="对方国家:中国:按6\n俄罗斯:按7\n美国:按8\n英国:按9\n法国:按10\n";
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(25);
}
cout<<endl;
for(int i=0;i<z.size();i++){
cout<<z[i];
Sleep(25);
}
cout<<endl;
int a,b;
sjfh:
cin>>a>>b;
if(a>5||a<1){
string t="错误!请重新输入!\n";
for(int i=0;i<t.size();i++){
cout<<t[i];
Sleep(25);
}
Sleep(1000);
goto sjfh;
}
if(b<6||b>10){
string t="错误!请重新输入!\n";
for(int i=0;i<t.size();i++){
cout<<t[i];
Sleep(25);
}
Sleep(1000);
goto sjfh;
}
system("cls");
s="请输入己方兵力:(不超过10000000000000000)\n";
z="请输入对方兵力:(不超过10000000000000000)\n";
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(25);
}
long long jfbl,dfbl;
cin>>jfbl;
for(int i=0;i<z.size();i++){
cout<<z[i];
Sleep(25);
}
cin>>dfbl;
PLUSvt(a,b,jfbl,dfbl);
}
else if(c=='4')
{
cout<<"欢迎下次使用,再见!";
break;
}
else
{
cout<<"错误!";
Sleep(1000);
goto start;
}
}
}