## [置顶]关于五子棋代码。求指导！！！

#include<iostream>
using namespace std;
void wz()
{
cout<<"下面开始五子棋比赛，一号选手用方块符号，二号用心型符号:"<<endl<<endl;
for(int i=3;i>0;i--)
{
cout<<i<<"  ";
}
cout<<"开始-----------"<<endl<<endl;
}

int hs()
{
int x,y,i=0,j=1;
char d[80][80];
//初始化---
for(x=0;x<25;x+=3)
{
for(y=0;y<80;y+=3)
{
d[x][y]='+';
}
}

//第一行数字--
for(x=0;x<10;x++)
cout<<x<<"  ";
for(x=10;x<27;x++)
cout<<x<<" ";
cout<<endl;

//输出棋盘--
for(x=0;x<25;x+=3)
{
cout<<j<<"  ";j++;
for(y=0;y<76;y+=3)
{

cout<<d[x][y]<<"  ";
}
cout<<endl;
}

while(1)
{

int a,b;
if(i%2==0)
cout<<"由玩家一下棋："<<endl;
else
cout<<"由玩家二下棋："<<endl;

cin>>a>>b;
if(i%2==1)
{
if(d[(a-1)*3][(b-1)*3]=='+')
d[(a-1)*3][(b-1)*3]=3;
else
{
cout<<"-----------------------------不能覆盖棋子:"<<endl;
continue;
}
}
else
{
if(d[(a-1)*3][(b-1)*3]=='+')
d[(a-1)*3][(b-1)*3]=1;
else
{
cout<<"-----------------------------不能覆盖棋子:"<<endl;
continue;
}
}
i++;
j=1;
//第一行数字---
for(x=0;x<10;x++)
cout<<x<<"  ";
for(x=10;x<27;x++)
cout<<x<<" ";
cout<<endl;

for(x=0;x<25;x+=3)
{
cout<<j<<"  ";j++;
for(y=0;y<76;y+=3)
{

cout<<d[x][y]<<"  ";
}
cout<<endl;
}
//判断是否是五个
if(//横着
d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1&&d[(a-1)*3][(b+2)*3]==1&&d[(a-1)*3][(b+3)*3]==1
||d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1&&d[(a-1)*3][(b+2)*3]==1
||d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1
||d[(a-1)*3][(b-4)*3]==1&&d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1
||d[(a-1)*3][(b-5)*3]==1&&d[(a-1)*3][(b-4)*3]==1&&d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//从左上到右下
||d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1&&d[(a+2)*3][(b+2)*3]==1&&d[(a+3)*3][(b+3)*3]==1
||d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1&&d[(a+2)*3][(b+2)*3]==1
||d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1
||d[(a-4)*3][(b-4)*3]==1&&d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1
||d[(a-5)*3][(b-5)*3]==1&&d[(a-4)*3][(b-4)*3]==1&&d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//从右上到左下
||d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[a-3][b+1]==1&&d[a-4][b+2]==1&&d[a-5][b+3]==1
||d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[(a-3)*3][(b+1)*3]==1&&d[(a-4)*3][(b+2)*3]==1
||d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[(a-3)*3][(b+1)*3]==1
||d[(a+2)*3][(b-4)*3]==1&&d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1
||d[(a+3)*3][(b-5)*3]==1&&d[(a+2)*3][(b-4)*3]==1&&d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//竖着
||d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1&&d[(a+2)*3][(b-1)*3]==1&&d[(a+3)*3][(b-1)*3]==1
||d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1&&d[(a+2)*3][(b-1)*3]==1
||d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1
||d[(a-4)*3][(b-1)*3]==1&&d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1
||d[(a-5)*3][(b-1)*3]==1&&d[(a-4)*3][(b-1)*3]==1&&d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1
)
{
cout<<endl<<"玩家一获胜"<<endl;break;
}

if(//横着
d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3&&d[(a-1)*3][(b+2)*3]==3&&d[(a-1)*3][(b+3)*3]==3
||d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3&&d[(a-1)*3][(b+2)*3]==3
||d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3
||d[(a-1)*3][(b-4)*3]==3&&d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3
||d[(a-1)*3][(b-5)*3]==3&&d[(a-1)*3][(b-4)*3]==3&&d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//从左上到右下
||d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3&&d[(a+2)*3][(b+2)*3]==3&&d[(a+3)*3][(b+3)*3]==3
||d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3&&d[(a+2)*3][(b+2)*3]==3
||d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3
||d[(a-4)*3][(b-4)*3]==3&&d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3
||d[(a-5)*3][(b-5)*3]==3&&d[(a-4)*3][(b-4)*3]==3&&d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//从右上到左下
||d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[a-3][b+1]==3&&d[a-4][b+2]==3&&d[a-5][b+3]==3
||d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[(a-3)*3][(b+1)*3]==3&&d[(a-4)*3][(b+2)*3]==3
||d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[(a-3)*3][(b+1)*3]==3
||d[(a+2)*3][(b-4)*3]==3&&d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3
||d[(a+3)*3][(b-5)*3]==3&&d[(a+2)*3][(b-4)*3]==3&&d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//竖着
||d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3&&d[(a+2)*3][(b-1)*3]==3&&d[(a+3)*3][(b-1)*3]==3
||d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3&&d[(a+2)*3][(b-1)*3]==3
||d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3
||d[(a-4)*3][(b-1)*3]==3&&d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3
||d[(a-5)*3][(b-1)*3]==3&&d[(a-4)*3][(b-1)*3]==3&&d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3
)
{
cout<<endl<<"玩家二获胜"<<endl;break;
}
}
return 0;
}
int main()
{
char a;
wz();
hs();
while(1)
{
cout<<"按P重新开始：";
cin>>a;
if(a=='p')
hs();
else
break;
}
return 0;
}

posted @ 2012-04-12 23:48 迎风而立 阅读(1250) | 评论 (5)编辑 收藏

## [置顶]关于移位运算符和取反运算符的一点感悟

#include<stdio.h>
int main()
{
char a=0x11;
char b;
b=~a<<2;
printf("%d\n",b);
b=~(a<<2);
printf("%d\n",b);
b=~a>>2;
printf("%d\n",b);
b=~(a>>2);
printf("%d\n",b);
return 0;
}

-72
-69
-5
-5

a=0x11=0001 0001

~a=1110 1110
a<<2=0100 0100
a>>2=0000 0100

~a<<2=1011 1000

1100 1000=-72  -72是十进制

~（a<<2）=0100 0100

~a>>2=1111 1011(注意现在是用1补齐的，因为~a的符号位是1)

~（a>>2)=1111 1011

posted @ 2012-04-08 21:29 迎风而立 阅读(1383) | 评论 (2)编辑 收藏

2012年4月12日

## 关于五子棋代码。求指导！！！

#include<iostream>
using namespace std;
void wz()
{
cout<<"下面开始五子棋比赛，一号选手用方块符号，二号用心型符号:"<<endl<<endl;
for(int i=3;i>0;i--)
{
cout<<i<<"  ";
}
cout<<"开始-----------"<<endl<<endl;
}

int hs()
{
int x,y,i=0,j=1;
char d[80][80];
//初始化---
for(x=0;x<25;x+=3)
{
for(y=0;y<80;y+=3)
{
d[x][y]='+';
}
}

//第一行数字--
for(x=0;x<10;x++)
cout<<x<<"  ";
for(x=10;x<27;x++)
cout<<x<<" ";
cout<<endl;

//输出棋盘--
for(x=0;x<25;x+=3)
{
cout<<j<<"  ";j++;
for(y=0;y<76;y+=3)
{

cout<<d[x][y]<<"  ";
}
cout<<endl;
}

while(1)
{

int a,b;
if(i%2==0)
cout<<"由玩家一下棋："<<endl;
else
cout<<"由玩家二下棋："<<endl;

cin>>a>>b;
if(i%2==1)
{
if(d[(a-1)*3][(b-1)*3]=='+')
d[(a-1)*3][(b-1)*3]=3;
else
{
cout<<"-----------------------------不能覆盖棋子:"<<endl;
continue;
}
}
else
{
if(d[(a-1)*3][(b-1)*3]=='+')
d[(a-1)*3][(b-1)*3]=1;
else
{
cout<<"-----------------------------不能覆盖棋子:"<<endl;
continue;
}
}
i++;
j=1;
//第一行数字---
for(x=0;x<10;x++)
cout<<x<<"  ";
for(x=10;x<27;x++)
cout<<x<<" ";
cout<<endl;

for(x=0;x<25;x+=3)
{
cout<<j<<"  ";j++;
for(y=0;y<76;y+=3)
{

cout<<d[x][y]<<"  ";
}
cout<<endl;
}
//判断是否是五个
if(//横着
d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1&&d[(a-1)*3][(b+2)*3]==1&&d[(a-1)*3][(b+3)*3]==1
||d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1&&d[(a-1)*3][(b+2)*3]==1
||d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1&&d[(a-1)*3][(b+1)*3]==1
||d[(a-1)*3][(b-4)*3]==1&&d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-1)*3][(b)*3]==1
||d[(a-1)*3][(b-5)*3]==1&&d[(a-1)*3][(b-4)*3]==1&&d[(a-1)*3][(b-3)*3]==1&&d[(a-1)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//从左上到右下
||d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1&&d[(a+2)*3][(b+2)*3]==1&&d[(a+3)*3][(b+3)*3]==1
||d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1&&d[(a+2)*3][(b+2)*3]==1
||d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1&&d[(a+1)*3][(b+1)*3]==1
||d[(a-4)*3][(b-4)*3]==1&&d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][b*3]==1
||d[(a-5)*3][(b-5)*3]==1&&d[(a-4)*3][(b-4)*3]==1&&d[(a-3)*3][(b-3)*3]==1&&d[(a-2)*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//从右上到左下
||d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[a-3][b+1]==1&&d[a-4][b+2]==1&&d[a-5][b+3]==1
||d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[(a-3)*3][(b+1)*3]==1&&d[(a-4)*3][(b+2)*3]==1
||d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1&&d[(a-3)*3][(b+1)*3]==1
||d[(a+2)*3][(b-4)*3]==1&&d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[(a-2)*3][b*3]==1
||d[(a+3)*3][(b-5)*3]==1&&d[(a+2)*3][(b-4)*3]==1&&d[(a+1)*3][(b-3)*3]==1&&d[a*3][(b-2)*3]==1&&d[(a-1)*3][(b-1)*3]==1
//竖着
||d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1&&d[(a+2)*3][(b-1)*3]==1&&d[(a+3)*3][(b-1)*3]==1
||d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1&&d[(a+2)*3][(b-1)*3]==1
||d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1&&d[(a+1)*3][(b-1)*3]==1
||d[(a-4)*3][(b-1)*3]==1&&d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1&&d[a*3][(b-1)*3]==1
||d[(a-5)*3][(b-1)*3]==1&&d[(a-4)*3][(b-1)*3]==1&&d[(a-3)*3][(b-1)*3]==1&&d[(a-2)*3][(b-1)*3]==1&&d[(a-1)*3][(b-1)*3]==1
)
{
cout<<endl<<"玩家一获胜"<<endl;break;
}

if(//横着
d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3&&d[(a-1)*3][(b+2)*3]==3&&d[(a-1)*3][(b+3)*3]==3
||d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3&&d[(a-1)*3][(b+2)*3]==3
||d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3&&d[(a-1)*3][(b+1)*3]==3
||d[(a-1)*3][(b-4)*3]==3&&d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-1)*3][(b)*3]==3
||d[(a-1)*3][(b-5)*3]==3&&d[(a-1)*3][(b-4)*3]==3&&d[(a-1)*3][(b-3)*3]==3&&d[(a-1)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//从左上到右下
||d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3&&d[(a+2)*3][(b+2)*3]==3&&d[(a+3)*3][(b+3)*3]==3
||d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3&&d[(a+2)*3][(b+2)*3]==3
||d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3&&d[(a+1)*3][(b+1)*3]==3
||d[(a-4)*3][(b-4)*3]==3&&d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][b*3]==3
||d[(a-5)*3][(b-5)*3]==3&&d[(a-4)*3][(b-4)*3]==3&&d[(a-3)*3][(b-3)*3]==3&&d[(a-2)*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//从右上到左下
||d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[a-3][b+1]==3&&d[a-4][b+2]==3&&d[a-5][b+3]==3
||d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[(a-3)*3][(b+1)*3]==3&&d[(a-4)*3][(b+2)*3]==3
||d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3&&d[(a-3)*3][(b+1)*3]==3
||d[(a+2)*3][(b-4)*3]==3&&d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[(a-2)*3][b*3]==3
||d[(a+3)*3][(b-5)*3]==3&&d[(a+2)*3][(b-4)*3]==3&&d[(a+1)*3][(b-3)*3]==3&&d[a*3][(b-2)*3]==3&&d[(a-1)*3][(b-1)*3]==3
//竖着
||d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3&&d[(a+2)*3][(b-1)*3]==3&&d[(a+3)*3][(b-1)*3]==3
||d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3&&d[(a+2)*3][(b-1)*3]==3
||d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3&&d[(a+1)*3][(b-1)*3]==3
||d[(a-4)*3][(b-1)*3]==3&&d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3&&d[a*3][(b-1)*3]==3
||d[(a-5)*3][(b-1)*3]==3&&d[(a-4)*3][(b-1)*3]==3&&d[(a-3)*3][(b-1)*3]==3&&d[(a-2)*3][(b-1)*3]==3&&d[(a-1)*3][(b-1)*3]==3
)
{
cout<<endl<<"玩家二获胜"<<endl;break;
}
}
return 0;
}
int main()
{
char a;
wz();
hs();
while(1)
{
cout<<"按P重新开始：";
cin>>a;
if(a=='p')
hs();
else
break;
}
return 0;
}

posted @ 2012-04-12 23:48 迎风而立 阅读(1250) | 评论 (5)编辑 收藏

2012年4月8日

## 关于移位运算符和取反运算符的一点感悟

#include<stdio.h>
int main()
{
char a=0x11;
char b;
b=~a<<2;
printf("%d\n",b);
b=~(a<<2);
printf("%d\n",b);
b=~a>>2;
printf("%d\n",b);
b=~(a>>2);
printf("%d\n",b);
return 0;
}

-72
-69
-5
-5

a=0x11=0001 0001

~a=1110 1110
a<<2=0100 0100
a>>2=0000 0100

~a<<2=1011 1000

1100 1000=-72  -72是十进制

~（a<<2）=0100 0100

~a>>2=1111 1011(注意现在是用1补齐的，因为~a的符号位是1)

~（a>>2)=1111 1011

posted @ 2012-04-08 21:29 迎风而立 阅读(1383) | 评论 (2)编辑 收藏

 < 2012年4月 >
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

• 随笔 - 2
• 文章 - 0
• 评论 - 3
• 引用 - 0

•