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 |
为什么是 运行时 错误?#include<iostream> using namespace std; int main() { int **flag; char **a; int m,n,k; int i ,j; int loop, len; bool f =true; while(cin>>m>>n>>k,n) { flag = new int*[m]; a= new char*[m]; for(int c =0; c<m; c++) { flag[c] = new int[n]; a[c] = new char[n+1]; } for(int kk =0; kk<m; kk++ ) for(int k = 0; k<n; k++) { flag[kk][k] = 0; cin>>a[kk][k]; } i = 0; j= k-1;len = 0;loop=1;f =true; while(j>=0&&i>=0&&j<n&&i<m&&f) { switch(a[i][j]) { case 'W': len++; flag[i][j]=1;j--; if(flag[i][j]==1) { flag[i][j]=2; while(1) { switch(a[i][j]) { case 'W': j--; loop++; break; case 'E': j++; loop++; break; case 'S':i++; loop++; break; case 'N': i--; loop++;break; } if(flag[i][j]==2) break; }//end while flag[i][j] = 0; cout<<len-loop+1<<" step(s) before a loop of "<<loop-1<<" step(s)"<<endl; f =false; break; } //end if break; case 'E': len++; flag[i][j]=1; j++; if(flag[i][j]==1) { flag[i][j]=2; while(1) { switch(a[i][j]) { case 'W': j--; loop++; break; case 'E': j++; loop++; break; case 'S':i++; loop++; break; case 'N': i--; loop++;break; } if(flag[i][j]==2) break; }//end while flag[i][j] = 0; cout<<len-loop+1<<" step(s) before a loop of "<<loop-1<<" step(s)"<<endl; f =false; break; } //end if break; case 'S': len++; flag[i][j]=1; i++; if(flag[i][j]==1) { flag[i][j]=2; while(1) { switch(a[i][j]) { case 'W': j--; loop++;break; case 'E': j++; loop++; break; case 'S':i++; loop++; break; case 'N': i--; loop++;break; } if(flag[i][j]==2) break; }//end while flag[i][j] = 0; cout<<len-loop+1<<" step(s) before a loop of "<<loop-1<<" step(s)"<<endl; f =false; break; } break; //end if case 'N': len++; flag[i][j]=1; i--; if(flag[i][j]==1) { flag[i][j]=2; while(1) { switch(a[i][j]) { case 'W': j--; loop++; break; case 'E': j++; loop++; break; case 'S': i++; loop++; break; case 'N': i--; loop++; break; } if(flag[i][j]==2) break; }//end while flag[i][j] = 0; cout<<len-loop+1<<" step(s) before a loop of "<<loop-1<<" step(s)"<<endl; f =false; break; } //end if break; } //end switch if(j<0||i<0||i>=m||j>=n) cout<<len<<" step(s) to exit"<<endl; }// while delete []a; delete []flag; }//end while } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator