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<string> using namespace std; char cha[21][21]; int visit[21][21]; int col,row; int mark(int i,int j) { if(i>0&&i<=row&&j>0&&j<=col&&cha[i][j]=='X'&&visit[i][j]==0) { visit[i][j]=1; mark(i-1,j-1); mark(i-1,j); mark(i-1,j+1); mark(i+1,j-1); mark(i+1,j); mark(i+1,j+1); mark(i,j-1); mark(i,j+1); } return 0; } int main() { int i,row1,col1,t,j; while(cin>>row>>col>>row1>>col1) { if(row==0&&col==0&&row1==0&&col1==0) break; memset(cha,'0',sizeof(cha));//就是这个函数。。哎!! for(i=1;i<=row;i++) { for(j=1;j<=col;j++) { cin>>cha[i][j]; } } memset(visit,0,sizeof(visit)); mark(row1,col1); t=0; for(i=1;i<=row;i++) { for(j=1;j<=col;j++) { if(visit[i][j]==1) { if(cha[i-1][j]!='X') { t++; } if(cha[i+1][j]!='X') { t++; } if(cha[i][j-1]!='X') { t++; } if(cha[i][j+1]!='X') { t++; } } } } cout<<t<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator