when i try to solve 10377,the gets() puzzled me a lot
[cpp]
#include "iostream.h"
#include "string.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
char maze[61][61],operation[1000],ori;
int numOfCase,row,column,temp,initX,initY,x,y,orient,flag;
cin>>numOfCase;
while(numOfCase>0)
{
orient=0;
numOfCase--;
cin>>row>>column;
//problem here,after i entered the value of row and column
//the gets() below will read the later automatically
//how can i solve this problem?
for(temp=0;temp<row;temp++)
{
gets(maze[temp]); //This gets()!!!
cout<<"maze["<<temp<<"]"<<endl;
}
cin>>initX>>initY;
x=initX;
y=initY;
while(1)
{
flag=0;
cin>>operation;
for(temp=0;temp<(int)strlen(operation);temp++)
{
switch(operation[temp])
{
case 'L':
orient--;
if (orient<0) orient=3;
break;
case 'R':
orient++;
if (orient>3) orient=0;
break;
case 'F':
switch(orient)
{
case 0:
if(maze[x-2][y-1]!='*') x--;
break;
case 1:
if(maze[x-1][y]!='*') y++;
break;
case 2:
if(maze[x][y-1]!='*') x++;
break;
case 3:
if(maze[x-1][y-2]!='*') y--;
break;
}
break;
case 'Q':
flag=1;
break;
}
if(flag==1) break;
}
if(flag==1) break;
}
switch(orient)
{
case 0:
ori='N';
break;
case 1:
ori='E';
break;
case 2:
ori='S';
break;
case 3:
ori='W';
break;
}
cout<<x<<" "<<y<<" "<<ori<<endl;
}
return 0;
}
[/cpp]
