Language: Java

#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <memory.h>
using namespace std;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int W, H, N;
int X1[1000], X2[1000], Y1[1000], Y2[1000];

bool fld[1000 * 6][1000 * 6];

int compress(int *x1, int *x2, int w) {
  vector<int> xs;

  for(int i = 0; i < N; i++) {
    for(int d = -1; d <= 1; d++) {
      int tx1 = x1[i] + d, tx2 = x2[i] + d;
      if(0 <= tx1 && tx1 <= w) xs.push_back(tx1);
      if(0 <= tx2 && tx2 <= w) xs.push_back(tx2);
    }
  }
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());

  for(int i = 0; i < N; i++) {
    x1[i] = find(xs.begin(),xs.end(),x1[i]) - xs.begin();
    x2[i] = find(xs.begin(),xs.end(),x2[i]) - xs.begin();
  }
  return xs.size();
}

void solve() {
  W = compress(X1,X2,W);
  H = compress(Y1,Y2,H);

  memset(fld,0,sizeof(fld));
  for(int i = 0; i < N; i++) {
    for(int y = Y1[i]; y <= Y2[i]; y++) {
      for(int x = X1[i]; x <= X2[i]; x++) {
        fld[y][x] = true;
      }
    }
  }


  int ans = 0;
  for(int y = 0; y < H; y++) {
    for(int x = 0; x < W; x++) {
      if(fld[y][x]) continue;
      ans++;

      queue<pair<int,int> > que;
      que.push(make_pair(x,y));
      while(!que.empty()) {
        int sx = que.front().first, sy = que.front().second;
        que.pop();

        for(int i = 0; i < 4; i++) {
          int tx = sx + dx[i], ty = sy + dy[i];
          if(tx < 0 || ty < 0 || tx >= W || ty >= H) continue;
          if(fld[ty][tx]) continue;
          que.push(make_pair(tx,ty));
          fld[ty][tx] = true;
        }
      }
    }
  }
  printf("%d\n",ans-1);
}


int main() {
  while(1) {
    scanf("%d %d",&W,&H);
    if(W == 0 && H == 0) break;
    W++;
    H++;
    scanf("%d",&N);
    for(int i = 0; i < N; i++) {
      scanf("%d %d %d %d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
      X1[i]++;
      Y1[i]++;
      X2[i]++;
      Y2[i]++;
    }
    solve();
  }
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <iostream>
^
Main.java:2: error: illegal character: '#'
#include <vector>
^
Main.java:3: error: illegal character: '#'
#include <math.h>
^
Main.java:4: error: illegal character: '#'
#include <stdio.h>
^
Main.java:5: error: illegal character: '#'
#include <algorithm>
^
Main.java:6: error: illegal character: '#'
#include <string>
^
Main.java:7: error: illegal character: '#'
#include <map>
^
Main.java:8: error: illegal character: '#'
#include <queue>
^
Main.java:9: error: illegal character: '#'
#include <memory.h>
^
Main.java:11: error: class, interface, enum, or record expected
int dx[] = {1,0,-1,0};
^
Main.java:12: error: class, interface, enum, or record expected
int dy[] = {0,1,0,-1};
^
Main.java:14: error: class, interface, enum, or record expected
int W, H, N;
^
Main.java:15: error: class, interface, enum, or record expected
int X1[1000], X2[1000], Y1[1000], Y2[1000];
^
Main.java:17: error: class, interface, enum, or record expected
bool fld[1000 * 6][1000 * 6];
^
Main.java:19: error: unnamed classes are a preview feature and are disabled by default.
int compress(int *x1, int *x2, int w) {
^
  (use --enable-preview to enable unnamed classes)
Main.java:19: error: <identifier> expected
int compress(int *x1, int *x2, int w) {
                ^
Main.java:19: error: class, interface, enum, or record expected
int compress(int *x1, int *x2, int w) {
                      ^
Main.java:22: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
  ^
Main.java:22: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
                 ^
Main.java:22: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
                        ^
Main.java:23: error: class, interface, enum, or record expected
    for(int d = -1; d <= 1; d++) {
                    ^
Main.java:23: error: class, interface, enum, or record expected
    for(int d = -1; d <= 1; d++) {
                            ^
Main.java:25: error: class, interface, enum, or record expected
      if(0 <= tx1 && tx1 <= w) xs.push_back(tx1);
      ^
Main.java:26: error: class, interface, enum, or record expected
      if(0 <= tx2 && tx2 <= w) xs.push_back(tx2);
      ^
Main.java:27: error: class, interface, enum, or record expected
    }
    ^
Main.java:30: error: class, interface, enum, or record expected
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  ^
Main.java:32: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
  ^
Main.java:32: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
                 ^
Main.java:32: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
                        ^
Main.java:34: error: class, interface, enum, or record expected
    x2[i] = find(xs.begin(),xs.end(),x2[i]) - xs.begin();
    ^
Main.java:35: error: class, interface, enum, or record expected
  }
  ^
Main.java:37: error: class, interface, enum, or record expected
}
^
Main.java:41: error: class, interface, enum, or record expected
  H = compress(Y1,Y2,H);
  ^
Main.java:43: error: class, interface, enum, or record expected
  memset(fld,0,sizeof(fld));
  ^
Main.java:44: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
  ^
Main.java:44: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
                 ^
Main.java:44: error: class, interface, enum, or record expected
  for(int i = 0; i < N; i++) {
                        ^
Main.java:45: error: class, interface, enum, or record expected
    for(int y = Y1[i]; y <= Y2[i]; y++) {
                       ^
Main.java:45: error: class, interface, enum, or record expected
    for(int y = Y1[i]; y <= Y2[i]; y++) {
                                   ^
Main.java:46: error: class, interface, enum, or record expected
      for(int x = X1[i]; x <= X2[i]; x++) {
                         ^
Main.java:46: error: class, interface, enum, or record expected
      for(int x = X1[i]; x <= X2[i]; x++) {
                                     ^
Main.java:48: error: class, interface, enum, or record expected
      }
      ^
Main.java:54: error: class, interface, enum, or record expected
  for(int y = 0; y < H; y++) {
  ^
Main.java:54: error: class, interface, enum, or record expected
  for(int y = 0; y < H; y++) {
                 ^
Main.java:54: error: class, interface, enum, or record expected
  for(int y = 0; y < H; y++) {
                        ^
Main.java:55: error: class, interface, enum, or record expected
    for(int x = 0; x < W; x++) {
                   ^
Main.java:55: error: class, interface, enum, or record expected
    for(int x = 0; x < W; x++) {
                          ^
Main.java:57: error: class, interface, enum, or record expected
      ans++;
      ^
Main.java:60: error: class, interface, enum, or record expected
      que.push(make_pair(x,y));
      ^
Main.java:61: error: class, interface, enum, or record expected
      while(!que.empty()) {
      ^
Main.java:63: error: class, interface, enum, or record expected
        que.pop();
        ^
Main.java:65: error: class, interface, enum, or record expected
        for(int i = 0; i < 4; i++) {
        ^
Main.java:65: error: class, interface, enum, or record expected
        for(int i = 0; i < 4; i++) {
                       ^
Main.java:65: error: class, interface, enum, or record expected
        for(int i = 0; i < 4; i++) {
                              ^
Main.java:67: error: class, interface, enum, or record expected
          if(tx < 0 || ty < 0 || tx >= W || ty >= H) continue;
          ^
Main.java:68: error: class, interface, enum, or record expected
          if(fld[ty][tx]) continue;
          ^
Main.java:69: error: class, interface, enum, or record expected
          que.push(make_pair(tx,ty));
          ^
Main.java:70: error: class, interface, enum, or record expected
          fld[ty][tx] = true;
          ^
Main.java:71: error: class, interface, enum, or record expected
        }
        ^
Main.java:76: error: class, interface, enum, or record expected
}
^
Main.java:82: error: class, interface, enum, or record expected
    if(W == 0 && H == 0) break;
    ^
Main.java:83: error: class, interface, enum, or record expected
    W++;
    ^
Main.java:84: error: class, interface, enum, or record expected
    H++;
    ^
Main.java:85: error: class, interface, enum, or record expected
    scanf("%d",&N);
    ^
Main.java:86: error: class, interface, enum, or record expected
    for(int i = 0; i < N; i++) {
    ^
Main.java:86: error: class, interface, enum, or record expected
    for(int i = 0; i < N; i++) {
                   ^
Main.java:86: error: class, interface, enum, or record expected
    for(int i = 0; i < N; i++) {
                          ^
Main.java:88: error: class, interface, enum, or record expected
      X1[i]++;
      ^
Main.java:89: error: class, interface, enum, or record expected
      Y1[i]++;
      ^
Main.java:90: error: class, interface, enum, or record expected
      X2[i]++;
      ^
Main.java:91: error: class, interface, enum, or record expected
      Y2[i]++;
      ^
Main.java:92: error: class, interface, enum, or record expected
    }
    ^
Main.java:94: error: class, interface, enum, or record expected
  }
  ^
73 errors