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

原因有二:数组开得太小;数组没有初始化,呵呵,我好久没有用到类了~~

Posted by gfedcba at 2009-03-01 22:43:56 on Problem 1656 and last updated at 2009-03-01 22:45:21
In Reply To:谁能帮我看一下,怎么就错了呢?????哪儿错了???? Posted by:11106113 at 2007-06-09 11:16:04
改成下面的代码,就AC了:

#include<iostream>
#include<string>
using namespace std;
const int N = 100;
class jin
{
public:
	jin();
	void black(int x,int y,int l);
    void white(int x,int y,int l);
    void test(int x,int y,int l);
private:
	// 开大一点
	int a[N+1][N+1];
};
int main()
{
	string word;
	jin hao;
	int b,x,y,l;
	cin>>b;
	for(int i=1;i<=b;i++)
	{
		cin>>word>>x>>y>>l;
		if(word=="BLACK")
		{
			hao.black(x,y,l);
		}
		else if(word=="WHITE")
		{
			hao.white(x,y,l);
		}
		else if(word=="TEST")
		{
			hao.test(x,y,l);
		}
	}
	return 0;
}

// 初始化
jin::jin()
{
	int i = 0;
	int j = 0;
	for (i=1; i<=N; i++)
	{
		for (j=0; j<=N; j++)
		{
			a[i][j] = 0;
		}
	}
}
void jin::black(int x,int y,int l)
{
	for(int j=x;j<=x+l-1;j++)
	{
		for(int k=y;k<=y+l-1;k++)
		{
			a[j][k]=1;
		}
	}
}
void jin::white(int x,int y,int l)
{
	for(int j=x;j<=x+l-1;j++)
	{
		for(int k=y;k<=y+l-1;k++)
		{
			a[j][k]=0;
		}
	}
}
void jin::test(int x,int y,int l)
{
	int m=0;
    for(int j=x;j<=x+l-1;j++)
	{
		for(int k=y;k<=y+l-1;k++)
		{
			if(a[j][k]==1)
				m++;
		}
	}
    cout<<m<<endl;
}


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