Language: C++

int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> s(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s.at(i).at(j);
        }
    }

    vector<vector<int>> ans(h, vector<int>(w));
    int num = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s.at(i).at(j) == '#') {
                ans.at(i).at(j) = num;
                
                int l = j - 1;
                while (0 <= l && s.at(i).at(l) == '.') {
                    s.at(i).at(l) = '#';
                    ans.at(i).at(l) = num;
                    l--;
                }

                int r = j + 1;
                while (r < w && s.at(i).at(r) == '.') {
                    s.at(i).at(r) = '#';
                    ans.at(i).at(r) = num;
                    r++;
                }
                j = r - 1;
                num++;
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        if (0 < ans.at(i).at(0)) continue;
        
        if (i == 0) {
            int a = i;
            while (ans.at(a).at(0) == 0) a++;
            
            a--;
            for (int y = a; y >= i; y--) {
                for (int j = 0; j < w; j++) {
                    ans.at(y).at(j) = ans.at(y + 1).at(j);
                }
            }
        }
        else if (i == h - 1) {
            int a = i;
            while (ans.at(a).at(0) == 0) a--;
            
            a++;
            for (int y = a; y <= i; y++) {
                for (int j = 0; j < w; j++) {
                    ans.at(y).at(j) = ans.at(y - 1).at(j);
                }
            }
        }
        else {
            for (int j = 0; j < w; j++) {
                ans.at(i).at(j) = ans.at(i - 1).at(j);
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans.at(i).at(j) << " ";
        }
        cout << endl;
    }

Compiler output:
a.cc:2:5: error: 'cin' does not name a type
    2 |     cin >> h >> w >> k;
      |     ^~~
a.cc:3:5: error: 'vector' does not name a type
    3 |     vector<vector<char>> s(h, vector<char>(w));
      |     ^~~~~~
a.cc:4:5: error: expected unqualified-id before 'for'
    4 |     for (int i = 0; i < h; i++) {
      |     ^~~
a.cc:4:21: error: 'i' does not name a type
    4 |     for (int i = 0; i < h; i++) {
      |                     ^
a.cc:4:28: error: 'i' does not name a type
    4 |     for (int i = 0; i < h; i++) {
      |                            ^
a.cc:10:5: error: 'vector' does not name a type
   10 |     vector<vector<int>> ans(h, vector<int>(w));
      |     ^~~~~~
a.cc:12:5: error: expected unqualified-id before 'for'
   12 |     for (int i = 0; i < h; i++) {
      |     ^~~
a.cc:12:21: error: 'i' does not name a type
   12 |     for (int i = 0; i < h; i++) {
      |                     ^
a.cc:12:28: error: 'i' does not name a type
   12 |     for (int i = 0; i < h; i++) {
      |                            ^
a.cc:36:5: error: expected unqualified-id before 'for'
   36 |     for (int i = 0; i < h; i++) {
      |     ^~~
a.cc:36:21: error: 'i' does not name a type
   36 |     for (int i = 0; i < h; i++) {
      |                     ^
a.cc:36:28: error: 'i' does not name a type
   36 |     for (int i = 0; i < h; i++) {
      |                            ^
a.cc:68:5: error: expected unqualified-id before 'for'
   68 |     for (int i = 0; i < h; i++) {
      |     ^~~
a.cc:68:21: error: 'i' does not name a type
   68 |     for (int i = 0; i < h; i++) {
      |                     ^
a.cc:68:28: error: 'i' does not name a type
   68 |     for (int i = 0; i < h; i++) {
      |                            ^