Language: C++

import java.util.*;
class Main {
    
    public static int[] dx = {-1, 0, 1, 0};
    public static int[] dy = {0, -1, 0, 1};
    public static void dfs(int x, int y, char[][] region, int n, int m)
    {
        char c = region[x][y];
        region[x][y] = 'x';
        
        for(int i=0;i<4;i++)
        {
            int new_x = x + dx[i];
            int new_y = y + dy[i];
            if(new_x >= 0 && new_x < n && new_y >= 0 && new_y < m && region[new_x][new_y] == c)
            {
                dfs(new_x, new_y, region,n, m);
            }
        }
        
    }
    
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            int m = sc.nextInt();
            int n = sc.nextInt();
            String temp = sc.nextLine();
            if(m==0&&n==0)
            {
                return;
            }
            // System.out.println(m+" "+n);
            char[][] region = new char[m][n];
            for(int i=0;i<m;i++)
            {
                // System.out.println(i);
                String line = sc.nextLine();
                // System.out.println(line);
                for(int j=0;j<n;j++)
                {
                    region[i][j] = line.charAt(j);
                }
            }
            
            int res = 0;
            for(int i=0;i<m;i++)
            {
                for(int j=0; j<n;j++)
                {
                    if(region[i][j] == 'x')
                        continue;
                    else
                    {
                        res += 1;
                        dfs(i,j, region, n, m);
                    }
                }
            }
            System.out.println(res);
        }
    }
}



Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:11: error: expected ':' before 'static'
    4 |     public static int[] dx = {-1, 0, 1, 0};
      |           ^~~~~~~
      |           :
a.cc:4:22: error: expected unqualified-id before '[' token
    4 |     public static int[] dx = {-1, 0, 1, 0};
      |                      ^
a.cc:5:11: error: expected ':' before 'static'
    5 |     public static int[] dy = {0, -1, 0, 1};
      |           ^~~~~~~
      |           :
a.cc:5:22: error: expected unqualified-id before '[' token
    5 |     public static int[] dy = {0, -1, 0, 1};
      |                      ^
a.cc:6:11: error: expected ':' before 'static'
    6 |     public static void dfs(int x, int y, char[][] region, int n, int m)
      |           ^~~~~~~
      |           :
a.cc:6:49: error: multidimensional array must have bounds for all dimensions except the first
    6 |     public static void dfs(int x, int y, char[][] region, int n, int m)
      |                                                 ^
a.cc:6:51: error: expected ',' or '...' before 'region'
    6 |     public static void dfs(int x, int y, char[][] region, int n, int m)
      |                                                   ^~~~~~
a.cc:23:11: error: expected ':' before 'static'
   23 |     public static void main(String args[]) {
      |           ^~~~~~~
      |           :
a.cc:23:29: error: 'String' has not been declared
   23 |     public static void main(String args[]) {
      |                             ^~~~~~
a.cc:64:2: error: expected ';' after class definition
   64 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::dfs(...)':
a.cc:8:18: error: 'region' was not declared in this scope
    8 |         char c = region[x][y];
      |                  ^~~~~~
a.cc:13:29: error: 'dx' was not declared in this scope; did you mean 'x'?
   13 |             int new_x = x + dx[i];
      |                             ^~
      |                             x
a.cc:14:29: error: 'dy' was not declared in this scope; did you mean 'y'?
   14 |             int new_y = y + dy[i];
      |                             ^~
      |                             y
a.cc:15:38: error: 'n' was not declared in this scope
   15 |             if(new_x >= 0 && new_x < n && new_y >= 0 && new_y < m && region[new_x][new_y] == c)
      |                                      ^
a.cc:15:65: error: 'm' was not declared in this scope
   15 |             if(new_x >= 0 && new_x < n && new_y >= 0 && new_y < m && region[new_x][new_y] == c)
      |                                                                 ^
a.cc: In static member function 'static void Main::main(int*)':
a.cc:24:9: error: 'Scanner' was not declared in this scope
   24 |         Scanner sc = new Scanner(System.in);
      |         ^~~~~~~
a.cc:27:21: error: 'sc' was not declared in this scope
   27 |             int m = sc.nextInt();
      |                     ^~
a.cc:29:13: error: 'String' was not declared in this scope
   29 |             String temp = sc.nextLine();
      |             ^~~~~~
a.cc:35:17: error: structured binding declaration cannot have type 'char'
   35 |             char[][] region = new char[m][n];
      |                 ^~
a.cc:35:17: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:35:17: error: empty structured binding declaration
a.cc:35:19: error: expected initializer before '[' token
   35 |             char[][] region = new char[m][n];
      |                   ^
a.cc:39:24: error: expected ';' before 'line'
   39 |                 String line = sc.nextLine();
      |                        ^~~~
a.cc:43:21: error: 'region' was not declared in this scope
   43 |                     region[i][j] = line.charAt(j);
      |                     ^~~~~~
a.cc:43:36: error: 'line' was not declared in this scope
   43 |                     region[i][j] = line.charAt(j);
      |                                    ^~~~
a.cc:52:24: error: 'region' was not declared in this scope
   52 |                     if(region[i][j] == 'x')
      |                        ^~~~~~
a.cc:61:13: error: 'System' was not declared in this scope
   61 |             System.out.println(res);
      |             ^~~~~~