Language: C++

using System;
using System.Collections.Generic;
using System.ComponentModel.Design;

class Program
{
	private static int h, w;
	private static char[][] m = new char[100][];
	private static int[] dx = new[] {0, 1, 0, -1, 1, 1, -1, -1};
	private static int[] dy = new[] {1, 0, -1, 0, 1, -1, 1, -1};
	public static int Main()
	{
		Scanner cin = new Scanner();
		while (true)
		{
			h = cin.nextInt();
			w = cin.nextInt();
			if (h == 0 || w == 0)
			{
				break;
			}
			int ans = 0;
			for (int i = 0; i < h; i++)
			{
				m[i] = cin.next().ToCharArray();
			}
			for (int i = 0; i < h; i++)
			{
				for (int j = 0; j < w; j++)
				{
					if (m[i][j] != '.')
					{
						dfs(i, j, m[i][j]);
						ans++;
					}
				}
			}
			Console.WriteLine(ans);
		}
		return 0;
	}

	public static void dfs(int x, int y, char nowchar)
	{
		m[x][y] = '.';
		for (int i = 0; i < 4; i++)
		{
			if (x + dx[i] < 0 || y + dy[i] < 0 || x + dx[i] == h || y + dy[i] == w || nowchar != m[x + dx[i]][y + dy[i]])
			{
				continue;
			}
			dfs(x + dx[i], y + dy[i], nowchar);
		}
	}
}

class Scanner {
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner() {
		s = new string[0];
		i = 0;
	}

	public string next() {
		if (i < s.Length) return s[i++];
		do {
			s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
		} while ((s.Length == 1 && s[0] == "") || s.Length == 0);
		i = 0;
		return s[i++];
	}

	public int nextInt() {
		return int.Parse(next());
	}

	public long nextLong() {
		return long.Parse(next());
	}

	public double nextDouble() {
		return double.Parse(next());
	}

}

Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.ComponentModel.Design;
      |       ^~~~~~
a.cc:7:16: error: expected ':' before 'static'
    7 |         private static int h, w;
      |                ^~~~~~~
      |                :
a.cc:8:16: error: expected ':' before 'static'
    8 |         private static char[][] m = new char[100][];
      |                ^~~~~~~
      |                :
a.cc:8:28: error: expected unqualified-id before '[' token
    8 |         private static char[][] m = new char[100][];
      |                            ^
a.cc:9:16: error: expected ':' before 'static'
    9 |         private static int[] dx = new[] {0, 1, 0, -1, 1, 1, -1, -1};
      |                ^~~~~~~
      |                :
a.cc:9:27: error: expected unqualified-id before '[' token
    9 |         private static int[] dx = new[] {0, 1, 0, -1, 1, 1, -1, -1};
      |                           ^
a.cc:10:16: error: expected ':' before 'static'
   10 |         private static int[] dy = new[] {1, 0, -1, 0, 1, -1, 1, -1};
      |                ^~~~~~~
      |                :
a.cc:10:27: error: expected unqualified-id before '[' token
   10 |         private static int[] dy = new[] {1, 0, -1, 0, 1, -1, 1, -1};
      |                           ^
a.cc:11:15: error: expected ':' before 'static'
   11 |         public static int Main()
      |               ^~~~~~~
      |               :
a.cc:43:15: error: expected ':' before 'static'
   43 |         public static void dfs(int x, int y, char nowchar)
      |               ^~~~~~~
      |               :
a.cc:55:2: error: expected ';' after class definition
   55 | }
      |  ^
      |  ;
a.cc: In static member function 'static int Program::Main()':
a.cc:13:17: error: 'Scanner' was not declared in this scope
   13 |                 Scanner cin = new Scanner();
      |                 ^~~~~~~
a.cc:16:29: error: 'cin' was not declared in this scope
   16 |                         h = cin.nextInt();
      |                             ^~~
a.cc:25:33: error: 'm' was not declared in this scope
   25 |                                 m[i] = cin.next().ToCharArray();
      |                                 ^
a.cc:31:45: error: 'm' was not declared in this scope
   31 |                                         if (m[i][j] != '.')
      |                                             ^
a.cc:38:25: error: 'Console' was not declared in this scope
   38 |                         Console.WriteLine(ans);
      |                         ^~~~~~~
a.cc: In static member function 'static void Program::dfs(int, int, char)':
a.cc:45:17: error: 'm' was not declared in this scope
   45 |                 m[x][y] = '.';
      |                 ^
a.cc:48:33: error: 'dx' was not declared in this scope; did you mean 'x'?
   48 |                         if (x + dx[i] < 0 || y + dy[i] < 0 || x + dx[i] == h || y + dy[i] == w || nowchar != m[x + dx[i]][y + dy[i]])
      |                                 ^~
      |                                 x
a.cc:48:50: error: 'dy' was not declared in this scope; did you mean 'y'?
   48 |                         if (x + dx[i] < 0 || y + dy[i] < 0 || x + dx[i] == h || y + dy[i] == w || nowchar != m[x + dx[i]][y + dy[i]])
      |                                                  ^~
      |                                                  y
a.cc:52:33: error: 'dx' was not declared in this scope; did you mean 'x'?
   52 |                         dfs(x + dx[i], y + dy[i], nowchar);
      |                                 ^~
      |                                 x
a.cc:52:44: error: 'dy' was not declared in this scope; did you mean 'y'?
   52 |                         dfs(x + dx[i], y + dy[i], nowchar);
      |                                            ^~
      |                                            y
a.cc: At global scope:
a.cc:58:9: error: 'string' does not name a type
   58 |         string[] s;
      |         ^~~~~~
a.cc:61:13: error: expected unqualified-id before '[' token
   61 |         char[] cs = new char[] { ' ' };
      |             ^
a.cc:63:15: error: expected ':' before 'Scanner'
   63 |         public Scanner() {
      |               ^~~~~~~~
      |               :
a.cc:68:15: error: expected ':' before 'string'
   68 |         public string next() {
      |               ^~~~~~~
      |               :
a.cc:68:16: error: 'string' does not name a type
   68 |         public string next() {
      |                ^~~~~~
a.cc:77:15: error: expected ':' before 'int'
   77 |         public int nextInt() {
      |               ^~~~
      |               :
a.cc:81:15: error: expected ':' before 'long'
   81 |         public long nextLong() {
      |               ^~~~~
      |               :
a.cc:85:15: error: expected ':' before 'double'
   85 |         public double nextDouble() {
      |               ^~~~~~~
      |               :
a.cc:89:2: error: expected ';' after class definition
   89 | }
      |  ^
      |  ;
a.cc: In constructor 'Scanner::Scanner()':
a.cc:64:17: error: 's' was not declared in this scope
   64 |                 s = new string[0];
      |                 ^
a.cc:64:25: error: 'string' does not name a type
   64 |                 s = new string[0];
      |                         ^~~~~~
a.cc: In member function 'int Scanner::nextInt()':
a.cc:78:24: error: expected primary-expression before 'int'
   78 |                 return int.Parse(next());
      |                        ^~~
a.cc:78:24: error: expected ';' before 'int'
a.cc:78:27: error: expected unqualified-id before '.' token
   78 |                 return int.Parse(next());
      |                           ^
a.cc: In member function 'long int Scanner::nextLong()':
a.cc:82:24: error: expected primary-expression before 'long'
   82 |                 return long.Parse(next());
      |                        ^~~~
a.cc:82:24: error: expected ';' before 'long'
a.cc:82:28: error: expected unqualified-id before '.' token
   82 |                 return long.Parse(next());
      |                            ^
a.cc: In member function 'double Scanner::nextDouble()':
a.cc:86:24: error: expected primary-expression before 'double'
   86 |                 return double.Parse(next());
      |                        ^~~~~~
a.cc:86:24: error: expected ';' before 'double'
a.cc:86:30: error: expected unqualified-id before '.' token
   86 |                 return double.Parse(next());
      |                              ^