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 |
大牛求救,wa#include <iostream> //#include <fstream> using namespace std; int main() { int n,count,row[9][2],col[9][2],matrix[9][2],i,j,k; char s[9][10]; int num = 1; //ifstream cin("a.txt"); cin>>n; while(n--){ for(i=0; i<9; i++) cin>>s[i]; for(i=0; i<9; i++){ row[i][0] = col[i][0] = matrix[i][0] = 9; row[i][1] = col[i][1] = matrix[i][1] = 0; } count=0; for(i=0; i<9; i++) for(j=0; j<9; j++){ if(s[i][j] == '0'){ row[i][0]--; col[j][0]--; matrix[(i/3)*3+j/3][0]--; count++; }else{ row[i][1]+=(s[i][j]-'0'); col[j][1]+=(s[i][j]-'0'); matrix[(i/3)*3+j/3][1]+=(s[i][j]-'0'); } } while(count){ for(i=0; i<9; i++) if(row[i][0] == 8){ j=0; while(s[i][j]!='0') j++; s[i][j] = 45-row[i][1]+'0'; row[i][0]++; col[j][0]++; matrix[i/3*3+j/3][0]++; col[j][1]+=(s[i][j]-'0'); matrix[i/3*3+j/3][1]+=(s[i][j]-'0'); row[i][1] = 45; count--; } for(j=0; j<9; j++) if(col[j][0] == 8){ i=0; while(s[i][j]!='0') i++; s[i][j] = 45-col[j][1]+'0'; row[i][0]++; col[j][0]++; matrix[i/3*3+j/3][0]++; row[i][1]+=(s[i][j]-'0'); matrix[i/3*3+j/3][1]+=(s[i][j]-'0'); col[j][1] = 45; count--; } for(k=0; k<9; k++) if(matrix[k][0] == 8){ int starti = k/3*3; int startj = (k-starti)*3; for(i=starti; i<starti+3; i++){ for(j=startj; j<startj+3; j++) if(s[i][j]=='0') break; if(s[i][j] == '0') break; } s[i][j] = 45-matrix[k][1]+'0'; row[i][0]++; col[j][0]++; matrix[i/3*3+j/3][0]++; row[i][1]+=(s[i][j]-'0'); col[j][1]+=(s[i][j]-'0'); matrix[i/3*3+j/3][1] = 45; count--; } } cout<<"Scenario #"<<num<<":"<<endl; for(i=0; i<9; i++) cout<<s[i]<<endl; cout<<endl; num++; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator