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 |
Re:过了的大神可以帮我看下我的代码,为什么不行吗?In Reply To:Re:过了的大神可以帮我看下我的代码,为什么不行吗? Posted by:13975 at 2015-07-17 12:15:41 #include<stdio.h> char data[20][20]; int flag[20][20],lineflag,n,m; void vervisit(int j,int k) { if(j-1>=0&&(data[j-1][k]=='|')&&!flag[j-1][k]) { flag[j-1][k]=1; vervisit(j-1,k); } if(j+1<n&&(data[j+1][k]=='|')&&!flag[j+1][k]) { flag[j+1][k]=1; vervisit(j+1,k); } } void horvisit(int j,int k) { if(k+1<m&&data[j][k+1]=='-'&&!flag[j][k+1]) { flag[j][k+1]=1; horvisit(j,k+1); } if(k-1>=0&&data[j][k-1]=='-'&&!flag[j][k-1]) { flag[j][k-1]=1; horvisit(j,k-1); } } void pievisit(int j,int k) { if((k+1<m)&&(j+1<n)&&(data[j+1][k+1]=='\\')&&!(flag[j+1][k+1])) { flag[j+1][k+1]=1; pievisit(j+1,k+1); } if((k-1>=0)&&(j-1>=0)&&(data[j-1][k-1]=='\\')&&!(flag[j-1][k-1])) { flag[j-1][k-1]=1; pievisit(j-1,k-1); } } void navisit(int j,int k) { if((k+1<m)&&(j-1>=0)&&(data[j-1][k+1]=='/')&&!(flag[j-1][k+1])) { flag[j-1][k+1]=1; navisit(j-1,k+1); } if((k-1>=0)&&(j+1<n)&&(data[j+1][k-1]=='/')&&!(flag[j+1][k-1])) { flag[j+1][k-1]=1; navisit(j+1,k-1); } } int main() { int t,i,j,k; scanf("%d",&t); for (i=0;i<t;i++) { lineflag=0; scanf("%d %d ",&n,&m); for(j=0;j<n;j++) { scanf("%s",data[j]); } for(j=0;j<n;j++) { for(k=0;k<m;k++) { if(!(flag[j][k])&&data[j][k]=='-') { flag[j][k]=1; horvisit(j,k); //把相关点置1,下面的遍历作用相同 lineflag++; continue; } if(!(flag[j][k])&&data[j][k]=='|') { flag[j][k]=1; vervisit(j,k); lineflag++; continue; } if(!(flag[j][k])&&data[j][k]=='\\') { flag[j][k]=1; pievisit(j,k); lineflag++; continue; } if(!(flag[j][k])&&data[j][k]=='/') { flag[j][k]=1; navisit(j,k); lineflag++; continue; } } } if(lineflag==1) { printf("CORRECT\n"); } else { printf("INCORRECT\n"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator