Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:跪求错误。。。有注释。

Posted by 2828 at 2010-04-09 01:37:18 on Problem 2918
In Reply To:跪求错误。。。有注释。 Posted by:2828 at 2010-04-09 01:35:22
> #include<iostream>
> 
> using namespace std;
> 
> char s[100][100];
> bool hash[100];
> 
> char find_num()
> {
> 	for(int i=1;i<=9;i++)
> 	{
> 		if(!hash[i])
> 			return (i+'0');
> 	}
> }
> 
> int main()
> {
> 	int test,i,j,t;
> 	scanf("%d",&test);//cin>>test;
> 	scanf("\n");
> 	for(t=0;t<test;t++)
> 	{
> 		for(i=0;i<9;i++)
> 			gets(s[i]);
> 		int mark=true;
> 		while(mark)
> 		{
> 			mark=false;
> 			for(i=0;i<9;i++)//每一行找出只有一个没有填的
> 			{
> 				int sumOfZero=0,position;
> 				memset(hash,false,sizeof(hash));
> 				for(j=0;j<9;j++)//9个数字
> 				{
> 					if('0'==s[i][j])
> 					{
> 						sumOfZero++;
> 						position=j;//记下第几个没填
> 						mark=true;
> 					}
> 					else
> 						hash[s[i][j]-'0']=true;//此数字已经有了
> 				}
> 				if(sumOfZero==1)//此行只有一个数字没有填,可以填了
> 				{
> 					s[i][position]=find_num();
> 				}
> 			}
> 			
> 			for(i=0;i<9;i++)//每一列找出只有一个没有填的
> 			{
> 				int sumOfZero=0,position;
> 				memset(hash,false,sizeof(hash));
> 				for(j=0;j<9;j++)
> 				{
> 					if('0'==s[j][i])
> 					{
> 						sumOfZero++;
> 						position=j;
> 						mark=true;
> 					}
> 					else
> 						hash[s[j][i]-'0']=true;
> 				}
> 				if(sumOfZero==1)
> 				{
> 					s[position][i]=find_num();
> 				}
> 			}
> 
> 			int x,y;
> 			for(i=0;i<9;i=i+3)//每一个块内找出只有一个没填的,一共有9块
> 			{
> 				for(j=0;j<9;j=j+3)
> 				{
> 					int sumOfZero=0,positionX,positionY,sum=0;
> 				    memset(hash,false,sizeof(hash));
> 					for(x=i;x<i+3;x++)
> 					{
> 						for(y=j;y<j+3;y++)
> 						{
> 							if(s[x][y]=='0')
> 							{
> 								sumOfZero++;
> 								positionX=x;
> 								positionY=y;
> 								mark=true;
> 							}
> 							else
> 								hash[s[x][y]-'0']=true;
> 						}
> 					}
> 					if(sumOfZero==1)
> 						s[positionX][positionY]=find_num();
> 				}
> 			}
> 		}
> 		cout<<"Scenario #"<<t+1<<":"<<endl;
> 		for(i=0;i<9;i++)
> 		{
> 			puts(s[i]);
> 		}
> 		cout<<endl;
> 	}return 0;
> }
> 	
> 	
> 	
> 
> 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator