fork download
  1. #include <stdio.h>
  2.  
  3. const int n =4;
  4. int data[n][n] = {
  5.  {3,3,2,5},
  6. {2,3,3,5},
  7. {1,1,3,1},
  8. {2,3,3,2}
  9. };
  10.  
  11. int dirs[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };
  12.  
  13. int *way=NULL;
  14. int way_cnt = 0;
  15.  
  16. int in_way (int r,int c) {
  17.  for (int i=0; i<way_cnt; i+=2) if (way[i]==r && way[i+1]==c) return 1;
  18.  return 0;
  19. }
  20.  
  21. void push_in_way (int r,int c) { way[way_cnt++] = r; way[way_cnt++] = c; }
  22.  
  23. int s (int seed,int r,int c) {
  24.  if (r<0 || r>n-1 || c<0 || c>n-1 || data[r][c]!=seed) return 0;
  25.  else {
  26.   int cnt = 1;
  27.   for (int dir=0; dir<4; dir++)
  28.   if (!in_way(r+dirs[dir][0],c+dirs[dir][1])) {
  29.   push_in_way (r+dirs[dir][0],c+dirs[dir][1]);
  30.   cnt+=s(seed,r+dirs[dir][0],c+dirs[dir][1]);
  31.   }
  32. return cnt;
  33. }
  34. }
  35.  
  36. int main(){
  37.  int seed_row = 3, seed_col = 1;
  38.  
  39.  way = new int [(n*n+4*n+4)*2];
  40.  if (way == NULL) return -1;
  41.  for (int i=0; i<n*n*2; i++) way[i]=-1;
  42.  way_cnt = 0;
  43.  
  44.  printf ("\nSeed data = %d",data[seed_row][seed_col]);
  45.  
  46.  push_in_way (seed_row,seed_col);
  47.  printf ("\nN=%d",s(data[seed_row][seed_col],seed_row,seed_col));
  48.  fflush (stdin);
  49.  getchar ();
  50.  return 0;
  51. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.pas:1: no include path in which to find stdio.h
stdout
Standard output is empty