Language: C++


import java.util.Scanner; 

 class Main{
 public static void main(String[] args){
 Scanner sc=new Scanner(System.in);
 int H=sc.nextInt();
 int W=sc.nextInt();
 char[][] k=new char[H][W];
 for(int i=0; i< H; i++){
 String line=sc.next();
 for(int j=0; j< W; j++){
 k[i][j]=line.charAt(j);
 }
 }
 int num=0;
 for(int i=0; i<H; i++){
 for(int j=0; j<W; j++){
 if(k[i][j]!=' '){
 dfs(i,j,H,W,k);
 num++;
 }
 }
 }
 System.out.println(num);
 }
 public static void dfs(int I,int J,final int H,final int W,char[][] k){
 char p=k[I][J];
 k[I][J]=' ';
 int[] dx={-1,0,0,1};
 int[] dy={0,-1,1,0};
 for(int t=0;t<4;t++){
 if(p==k[I+dx[t]][J+dy[t]]&&I+dx[t]>=0&&I+dx[t]<H&&J+dy[t]>=0&&J+dy[t]<W){
 dfs(I+dx[t],J+dy[t],H,W,k);
 }
 }
 return;
 }
 }

Compiler output:
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.Scanner;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:8: error: expected ':' before 'static'
    5 |  public static void main(String[] args){
      |        ^~~~~~~
      |        :
a.cc:5:26: error: 'String' has not been declared
    5 |  public static void main(String[] args){
      |                          ^~~~~~
a.cc:5:35: error: expected ',' or '...' before 'args'
    5 |  public static void main(String[] args){
      |                                   ^~~~
a.cc:27:8: error: expected ':' before 'static'
   27 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |        ^~~~~~~
      |        :
a.cc:27:37: error: 'final' has not been declared
   27 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                     ^~~~~
a.cc:27:37: error: two or more data types in declaration of 'H'
a.cc:27:48: error: expected ')' before ',' token
   27 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                        ~                       ^
      |                                                )
a.cc:27:49: error: variable or field 'final' declared void
   27 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                                 ^~~~~
a.cc:27:49: error: expected ';' at end of member declaration
   27 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                                 ^~~~~
      |                                                      ;
a.cc:27:61: error: expected unqualified-id before 'char'
   27 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                                             ^~~~
a.cc:39:3: error: expected ';' after class definition
   39 |  }
      |   ^
      |   ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:6:2: error: 'Scanner' was not declared in this scope
    6 |  Scanner sc=new Scanner(System.in);
      |  ^~~~~~~
a.cc:7:8: error: 'sc' was not declared in this scope
    7 |  int H=sc.nextInt();
      |        ^~
a.cc:9:6: error: structured binding declaration cannot have type 'char'
    9 |  char[][] k=new char[H][W];
      |      ^~
a.cc:9:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:9:6: error: empty structured binding declaration
a.cc:9:8: error: expected initializer before '[' token
    9 |  char[][] k=new char[H][W];
      |        ^
a.cc:11:2: error: 'String' was not declared in this scope
   11 |  String line=sc.next();
      |  ^~~~~~
a.cc:13:2: error: 'k' was not declared in this scope
   13 |  k[i][j]=line.charAt(j);
      |  ^
a.cc:13:10: error: 'line' was not declared in this scope
   13 |  k[i][j]=line.charAt(j);
      |          ^~~~
a.cc:19:5: error: 'k' was not declared in this scope
   19 |  if(k[i][j]!=' '){
      |     ^
a.cc:25:2: error: 'System' was not declared in this scope
   25 |  System.out.println(num);
      |  ^~~~~~