[ create a new paste ] login | about

Link: http://codepad.org/dbAilHJZ    [ raw code | output | fork ]

yifan666 - C, pasted on Aug 10:
// maze
#include<iostream>
#include<conio.h>
#define nMax 100
using namespace std;
char matrix[nMax][nMax];
bool isReached;
void visit(char matrix[nMax][nMax], int x,int y){
 if(matrix[x][y] == '3'){
  isReached = true; return;
 }
 matrix[x][y] = '1';
 if(isReached == false && x-1 >=0 && (matrix[x-1][y] == '0' || matrix[x-1][y] == '3')) visit(matrix,x-1,y);
 if(isReached == false && x+1 <nMax && (matrix[x+1][y] == '0' || matrix[x+1][y] == '3')) visit(matrix,x+1,y);
 if(isReached == false && y-1 >=0 && (matrix[x][y-1] == '0' || matrix[x][y-1] == '3')) visit(matrix,x,y-1);
 if(isReached == false && y+1 <nMax && (matrix[x][y+1] == '0' || matrix[x][y+1] == '3')) visit(matrix,x,y+1);
}
int main(){
 freopen("MAZE.INP","r", stdin);
 freopen("MAZE.OUT","w", stdout);
 int testCase;
 int loop =1;
 int beginX, beginY;
 while(loop++ <= 10){
  isReached = false;
  cin>>testCase;
  for(int i=0;i<nMax;i++){
   cin>>matrix[i];
   for(int j=0;j<nMax;j++)
    if(matrix[j][i] == '2'){
     beginX = j; beginY = i;
   }
  }
  visit(matrix,beginX,beginY);
  if(isReached){
   cout<<"#"<<testCase<<" "<<1<<endl;
  }else{
   cout<<"#"<<testCase<<" "<<0<<endl;
  }
  
 }
 return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Line 18: error: iostream: No such file or directory
Line 17: error: conio.h: No such file or directory
Line 5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
Line 7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'isReached'
In function 'visit':
Line 10: error: 'isReached' undeclared (first use in this function)
Line 10: error: (Each undeclared identifier is reported only once
Line 10: error: for each function it appears in.)
Line 10: error: 'true' undeclared (first use in this function)
Line 13: error: 'false' undeclared (first use in this function)
In function 'main':
Line 25: error: 'isReached' undeclared (first use in this function)
Line 25: error: 'false' undeclared (first use in this function)
Line 26: error: 'cin' undeclared (first use in this function)
Line 27: error: 'for' loop initial declaration used outside C99 mode
Line 29: error: 'for' loop initial declaration used outside C99 mode
Line 36: error: 'cout' undeclared (first use in this function)
Line 36: error: 'endl' undeclared (first use in this function)


Create a new paste based on this one


Comments: