| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 319 人关注过本帖
标题:哪位高手帮偶找一下这程序的错误
收藏  订阅  推荐  打印 
warriorguo
Rank: 1
等级:新手上路
帖子:5
积分:150
注册:2005-5-28
哪位高手帮偶找一下这程序的错误

这是一个九宫填数的程序,用的是穷举的方法~

偶是菜鸟~~不只这中有什么逻辑错误

请各位帮帮~~小弟先说谢谢了啊

int A[9],M[3][3];

void print(int mm){ int j; FILE* ff; ff=fopen("result.txt","w"); if (mm==1){ for (j=1;j<=9;j++){ if (!(j%3)) fputc('\n',ff); fprintf(ff,"%d ",M[(j-1)/3][(j-1)%3]); } fclose(ff); exit(0); }else{ fputs("Not Fount!\n",ff); fclose(ff); } } int check(){ int i,j; int temp1=0, temp2=0, temp3=0, temp4=0, temp5=0, temp6=0; for (i=0;i<3;i++){ for (j=0;j<3;j++){ temp1+=M[i][j]; temp2+=M[j][i]; } if (temp1!=temp2) return 0; if ((temp3!=0)&&(temp4!=0)&&(temp3!=temp1)&&(temp4!=temp2)) return 0; temp3=temp1; temp4=temp2; } for (i=0;i<3;i++){ temp5+=M[i][i]; temp6+=M[2-i][2-i]; } if((temp5!=temp6)&&(temp4!=temp5)) return 0; return 1; }

int main(){ int i,j,temp=0;

for (i=1;i<=9;i++) A[i-1]=i; printf("Please wait a minuts......"); i=0; while(1){ i=i%8; temp=A[i]; A[i]=A[i+1]; A[i+1]=temp; i++;

for (j=0;j<9;j++) M[j/3][j%3]=A[j]; if (check()){ print(1); } }print(0); return 1; }

2005-5-28 20:24
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.046332 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved