该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Scanner in = new Scanner(System.in);
final int SIZE =3;
int[][] board = new int[SIZE][SIZE];
boolean gotResult = false;
int numofx = 0;
int numofo = 0;
// 读入矩阵
for(int i=0; i
{
for(int j=0; j
{
board[i][j] = in.nextInt();
}
}
// 检查行
if(!gotResult)
{
for(int i=0; i
{
numofx =0;
numofo =0;
for(int j=0; j
{
if(board[i][j] ==1)
{
numofx ++;
}
else
{
numofo ++;
}
}
if(numofx ==SIZE|| numofo ==SIZE)
{
gotResult = true;
break;
}
}
}
// 检查列
if(!gotResult)
{
for(int i=0; i
{
numofx =0;
numofo =0;
for(int j=0; j
{
if(board[j][i] ==1)
{
numofx ++;
}
else
{
numofo ++;
}
}
if(numofx == SIZE|| numofo ==SIZE)
{
gotResult = true;
break;
}
}
}
//检查对角线
if(!gotResult)
{
numofo =0;
numofx =0;
for(int i=0; i
{
if(board[i][i] ==1)
{
numofx ++;
}
else
{
numofo ++;
}
}
if(numofx ==SIZE|| numofo ==SIZE)
{
gotResult = true;
}
}
// 检查反对角线
if(!gotResult)
{
numofx =0;
numofo =0;
for(int i=0; i
{
if(board[i][SIZE-i-1] ==1)
{
numofx ++;
}
else
{
numofo ++;
}
}
if(numofx ==SIZE|| numofo ==SIZE)
{
gotResult = true;
}
}
if(gotResult)
{
if(numofx == SIZE)
{
System.out.println(1+"赢了");
}
else
{
System.out.println(0+"赢了");
}
}