首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

帮忙看一下异常之处

2012-05-09 
帮忙看一下错误之处[codeC/C++][/code]#includestdio.h#define MAXSIZE 1000struct CurState{int s[9][

帮忙看一下错误之处
[code=C/C++][/code]#include"stdio.h"
#define MAXSIZE 1000
struct CurState
{
int s[9][9];
int rule;
}solution[MAXSIZE];
int deep=0;
int destination[9][9]={{0,1,2,3,4,5,6,7,8},{9,10,11,12,13,14,15,16,17},
{18,19,20,21,22,23,24,25,26},{27,28,29,30,31,32,33,34,35},
{36,37,38,39,40,41,42,43,44},{45,46,47,48,49,50,51,52,53},
{54,55,56,57,58,59,60,61,62},{63,64,65,66,67,68,69,70,71},
{72,73,74,75,76,77,78,79,80}};
int IsDestination(int t) //判断是否是目标状态 ,目标状态,返回1,否则0 
{
int flag,i,j;
flag=0;
for(i=0;i<9;i++)
for(j=0;j<9;j++)
if(solution[t].s[i][j]!=destination[i][j])
flag=1;
if(flag) return 0;
else return 1;
}
int IsHad(int t) //判断是否是原来经过的状态 ,经过,返回 0,否则1 
{
int i,j,k,flag=0;
for(i=0;i<t;i++)
{
for(j=0;j<9;j++)
for(k=0;k<9;k++)
if(solution[i].s[j][k]!=solution[t].s[j][k])
flag=1;
}
if(flag) return 1;
else return 0;
}
int ISBeyond(int t) //判断是否越界 ,越界返回1,否则0 
{
int i,j,x,y;
for(i=0;i<9;i++)
for(j=0;j,9;j++)
if(destination[t].s[i][j]==0)
{
x=i;y=j;
}
if(destination[t].rule==0&&x==0)
return 1;
else if(destination[t].rule==1&&y==o)
return 1;
else if(destination[t].rule==2&&x==8)
return 1;
else if(destination[t].rule==3&&y==8)
return 1;
else return 0;
}
void Turn(int t) //按rule交换 
{
int i,j,x,y,temp;
for(i=0;i<9;i++)
for(j=0;j,9;j++)
if(destination[t].s[i][j]==0)
{
x=i;y=j;
}
if(destination[t].rule==0)
{
for(i=0;i<9;i++)
for(j=0;j<9;j++)
destination[t+1].s[i][j]=destination[t].s[i][j];
destination[t+1].s[x][y]=destination[t].s[x-1][y];
destination[t+1].s[x-1][y]=0;
}

if(destination[t].rule==1)
{
for(i=0;i<9;i++)
for(j=0;j<9;j++)
destination[t+1].s[i][j]=destination[t].s[i][j];
destination[t+1].s[x][y]=destination[t].s[x][y-1];
destination[t+1].s[x][y-1]=0;
}
if(destination[t].rule==2)
{
for(i=0;i<9;i++)
for(j=0;j<9;j++)
destination[t+1].s[i][j]=destination[t].s[i][j];
destination[t+1].s[x][y]=destination[t].s[x+1][y];
destination[t+1].s[x+1][y]=0;
}
if(destination[t].rule==3)
{
for(i=0;i<9;i++)
for(j=0;j<9;j++)
destination[t+1].s[i][j]=destination[t].s[i][j];
destination[t+1].s[x][y]=destination[t].s[x][y+1];
destination[t+1].s[x][y+1]=0;
}
}
int main()
{
int i,j,k,flag=0;
solution[0].s[9][9]={{1,2,3,4,13,5,6,7,8},{9,10,11,12,22,14,15,16,17},
{18,19,20,21,31,23,24,25,26},{27,28,29,30,40,32,33,34,35},
{36,37,38,39,49,41,42,43,44},{45,46,47,48,58,50,51,52,53},
{54,55,56,57,0,59,60,61,62},{63,64,65,66,67,68,69,70,71},
{72,73,74,75,76,77,78,79,80}};
while(!IsDestination)
{
while(t>=MAXSIZE)
printf("空间已满,未找到路径");
if(rule>3)
{
t--;
solution[t].rule++;
deep--;
}
else 
{
if(!IsHad)
{
t--;
solution[t].rule++
deep--;
}
else
if(!ISBeyond)
{
Turn(t);
deep++;
t++;
}
else
solution[t].rule++;
}
}
for(i=0;i<deep;i++)
for(j=o;j<9;j++)
for(k=0;k<9;k++)
{
printf("%3d",solution[i].s[j][k]);
flag++;
if(flag%9==0)
printf("\n");
}
}

编译显示错误如下:
[Error] C:\Users\U\Documents\C-Free\Temp\未命名2.cpp:43: error: request for member `s' in `destination[t]', which is of non-class type `int[9]'


不知是怎么回事,求人指点一下

[解决办法]
solution[t].s[i][j]!=destination[i][j]二维数组不能这样直接比较吧,要一个个元素比较
[解决办法]

探讨

麻烦帮我看看,只要告诉我
[Error] C:\Users\U\Documents\C-Free\Temp\未命名2.cpp:43: error: request for member `s' in `destination[t]', which is of non-class type `int[9]'
这个错误是什么原因就行,要麻烦大家帮我运行一下额

热点排行