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 |
原因有二:数组开得太小;数组没有初始化,呵呵,我好久没有用到类了~~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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator