Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
RE!!!附代码,求牛人指教#include<stdio.h> char a[9][7000000]; int r[9][10],c[9][10],z[3][3][10]; struct { int x,y; }b[82]; main() { int n; scanf("%d",&n); for(int nn=1;nn<=n;nn++) { gets(a[0]); int bb=0; for(int i=0;i<9;i++) { gets(a[i]); int k=0; for(int j=0;j<9;j++) { while((a[i][k]<'0')||(a[i][k]>'9'))k++; a[i][j]=a[i][k]; k++; } a[i][9]=0; for(int j=0;j<9;j++) { if(a[i][j]=='0') { b[bb].x=i; b[bb].y=j; bb++; } else r[i][a[i][j]-'0']=c[j][a[i][j]-'0']=z[i/3][j/3][a[i][j]-'0']=1; } } int i=0; while(i<bb) { int j=a[b[i].x][b[i].y]-'0'+1; for(;j<10;j++) { if((!r[b[i].x][j])&&(!c[b[i].y][j])&&(!z[b[i].x/3][b[i].y/3][j])) { r[b[i].x][j]=c[b[i].y][j]=z[b[i].x/3][b[i].y/3][j]=1; a[b[i].x][b[i].y]=j+'0'; break; } } if(j<10) { i++; if(i<bb)a[b[i].x][b[i].y]='0'; } else { i--; r[b[i].x][a[b[i].x][b[i].y]-'0']=c[b[i].y][a[b[i].x][b[i].y]-'0']=z[b[i].x/3][b[i].y/3][a[b[i].x][b[i].y]-'0']=0; } } printf("Scenario #%d:\n",nn); for(int i=0;i<9;i++)puts(a[i]); puts(""); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator