fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n;
  5. bool ways(int x,int y, int mat[n][n], int res[n][n]);
  6. void printsol(int res[n][n]);
  7. int main()
  8. {
  9. cin>>n;
  10. int mat[n][n];
  11. int res[n][n];
  12. for(int i=0;i<n;i++)
  13. for(int j=0;j<n;j++)
  14. cin>>mat[i][j];
  15.  
  16. for(int i=0;i<n;i++)
  17. {
  18. for(int j=0;j<n;j++)
  19. {
  20. if(mat[i][j]==0)
  21. res[i][j]=-1;
  22. else res[i][j]=0;
  23. }
  24. }
  25.  
  26. if(ways(0,0,mat,res)==true)
  27. printsol(res);
  28. else
  29. cout<<no solution found;
  30.  
  31. return 0;
  32. }
  33.  
  34. void printsol(int res[n][n])
  35. {
  36. for(int i=0;i<n;i++)
  37. {
  38. for(int j=0;j<n;j++)
  39. cout<<res[i][j]<<" ";
  40. cout<<endl;
  41. }
  42. }
  43.  
  44. bool ways(int x,int y, int mat[n][n], int res[n][n])
  45. {
  46. if(res[n-1][n-1]==1)
  47. return true;
  48. if(mat[x][y]==1)
  49. {
  50. res[x][y]=1;
  51. if(ways(x+1,y,mat,res)==true)
  52. {
  53. return true;
  54. }
  55. if(ways(x,y+1,mat,res)==true)
  56. {
  57. return true;
  58. }
  59. res[x][y]=0;
  60. return false;
  61. }
  62. }
  63.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:33: error: array bound is not an integer constant before ‘]’ token
 bool ways(int x,int y, int mat[n][n], int res[n][n]);
                                 ^
prog.cpp:5:36: error: array bound is not an integer constant before ‘]’ token
 bool ways(int x,int y, int mat[n][n], int res[n][n]);
                                    ^
prog.cpp:5:37: error: expected ‘)’ before ‘,’ token
 bool ways(int x,int y, int mat[n][n], int res[n][n]);
                                     ^
prog.cpp:5:39: error: expected unqualified-id before ‘int’
 bool ways(int x,int y, int mat[n][n], int res[n][n]);
                                       ^~~
prog.cpp:6:24: error: array bound is not an integer constant before ‘]’ token
 void printsol(int res[n][n]);
                        ^
prog.cpp:6:27: error: array bound is not an integer constant before ‘]’ token
 void printsol(int res[n][n]);
                           ^
prog.cpp: In function ‘int main()’:
prog.cpp:29:9: error: ‘no’ was not declared in this scope
   cout<<no solution found;
         ^~
prog.cpp: At global scope:
prog.cpp:34:24: error: array bound is not an integer constant before ‘]’ token
 void printsol(int res[n][n])
                        ^
prog.cpp:34:27: error: array bound is not an integer constant before ‘]’ token
 void printsol(int res[n][n])
                           ^
prog.cpp: In function ‘void printsol(...)’:
prog.cpp:39:10: error: ‘res’ was not declared in this scope
    cout<<res[i][j]<<" ";
          ^~~
prog.cpp: At global scope:
prog.cpp:44:33: error: array bound is not an integer constant before ‘]’ token
 bool ways(int x,int y, int mat[n][n], int res[n][n])
                                 ^
prog.cpp:44:36: error: array bound is not an integer constant before ‘]’ token
 bool ways(int x,int y, int mat[n][n], int res[n][n])
                                    ^
prog.cpp:44:37: error: expected ‘)’ before ‘,’ token
 bool ways(int x,int y, int mat[n][n], int res[n][n])
                                     ^
prog.cpp:44:39: error: expected unqualified-id before ‘int’
 bool ways(int x,int y, int mat[n][n], int res[n][n])
                                       ^~~
stdout
Standard output is empty