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

大牛帮忙啊 为什么wa啊!!!!!

Posted by mysf at 2009-11-11 15:24:24 on Problem 2918
#include <iostream>
using namespace std;

int main()
{
	//freopen("a.in","r",stdin);
	int a[10][10]={0};
	int i, j, n;
	cin>>n;
	for (int mm=1; mm<=n; mm++)
	{
		int sum=0;
		for (i=1; i<=9; i++)
			for (j=1; j<=9; j++)
			{
				char c;
				cin>>c;
				while (c<'0' || c>'9') cin>>c;
				
				a[i][j]=c-'0';
				if (a[i][j]==0) sum++;
			};
		while (sum!=0)
		{
			for (i=1; i<=9; i++)
				for (j=1; j<=9; j++)
				{
					if (a[i][j]==0) 
					{
						int sum0=0;
						int summ=0;
						for (int p=1; p<=9; p++)
						{
							if (a[i][p]==0) sum0++;
							summ+=a[i][p];
						}
						if (sum0==1) 
						{
							a[i][j]=45-summ;
							sum--;
							goto loop;
						}
						sum0=0;
						summ=0;
						for (int p=1; p<=9; p++)
						{
							if (a[p][j]==0) sum0++;
							summ+=a[p][j];
						}
						if (sum0==1) 
						{
							a[i][j]=45-summ;
							sum--;
							goto loop;
						}
					}
					if (a[i][j]==0)
					{
						int sum0=0;
						int summ=0;
						for (int p=(i/3)*3+1; p<=(i/3)*3+3; p++)
							for (int q=(j/3)*3+1; q<=(j/3)*3+3; q++)
							{
								if (a[p][q]==0) sum0++;
								summ+=a[p][q];
							};
						if (sum0==1)
						{
							a[i][j]=45-summ;
							sum--;
							goto loop;
						}

					}

				}
loop:;
		}
		cout<<"Scenario #"<<mm<<":"<<endl;
		for (i=1; i<=9; i++)
		{
			for (j=1; j<=9; j++)
			{
				cout<<a[i][j];
			}
			cout<<endl;
		}
		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