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 <vector> using namespace std; char map[50][50]; bool flag[50][50]; int main() { int x , y , k; int step=0 , loop = 0; cin >> x>> y>>k; while (x != 0) { memset( flag,false,sizeof(flag) ); for (int x1 =0 ; x1 < x ; x1++) { for (int y1 = 0; y1 < y ; y1++) { cin >> map[x1][y1]; } } int x2 = 0 , y2 = k-1; while ( ( !( x2<0 || y2<0 || x2>x || y2>y ) ) && flag[x2][y2] == false) { flag[x2][y2] = true; switch( map[x2][y2] ) { case 'E': { y2++; break; } case 'W': { y2--; break; } case 'S': { x2++; break; } case 'N': { x2--; break; } default : break; } step++; } if ( x2<0 || y2<0 || x2>x || y2>y) memset( flag,false,sizeof(flag) ); if ( flag[x2][y2] == true ) { memset( flag,false,sizeof(flag) ); while (flag[x2][y2] == false) { flag[x2][y2] = true; switch( map[x2][y2] ) { case 'E': y2++; break; case 'W': y2--; break; case 'S': x2++; break; case 'N': x2--; break; default : break; } loop++; } } if ( loop == 0 ) cout <<step<<" step(s) to exit"<<endl; else cout <<step-loop<<" step(s) before a loop of "<<loop<<" step(s)"<<endl; step = 0; loop = 0; cin >> x>> y>>k; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator