online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
// Link - https://www.spoj.com/problems/ABCPATH/ #include <bits/stdc++.h> using namespace std ; char mat[52][52] ; int dp[52][52] ; int h = 0 , w = 0 ; int ans = INT32_MIN ; bool valid ( int x , int y , int prev , int curr ) { if ( x < 1 || x > 50 || y < 1 || y > 50 ) return 0 ; if ( curr-prev != 1 ) return 0 ; return 1 ; } int xc[] = {-1,-1,-1,0,+1,+1,+1,0} ; int yc[] = {-1,0,+1,+1,+1,0,-1,-1} ; void dfs ( int x , int y , char let , int dis ) { ans = max ( ans , dis ) ; for ( int i = 0 ; i < 8 ; i++ ) { int nx = x+xc[i] ; int ny = y+yc[i] ; if ( valid(nx,ny,let,mat[nx][ny]) ) { dfs(nx,ny,mat[nx][ny],dis+1) ; } } } int32_t main () { int Case = 1 ; while (true) { for ( int i = 1 ; i <= h ; i++ ) { for ( int j = 1 ; j <= w ; j++ ) { mat[i][j] = '#' ; } } for ( int i = 1 ; i <= h ; i++ ) { for ( int j = 1 ; j <= w ; j++ ) { dp[i][j] = -1 ; } } cin >> h >> w ; if ( h == 0 and w == 0 ) break ; for ( int i = 1 ; i <= h ; i++ ) { for ( int j = 1 ; j <= w ; j++ ) { cin >> mat[i][j] ; } } for ( int i = 1 ; i <= h ; i++ ) { for ( int j = 1 ; j <= w ; j++ ) { if ( mat[i][j] == 'A' ) dfs(i,j,mat[i][j],1) ; } } cout << "Case " << Case << ": " << ans << "\n" ; Case++ ; } return 0 ; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue