Language: C++

#include<iostream>
#include<vector>
using namespace std;

const int MAX_H = 301;
const int MAX_W = 301;
char data[MAX_H][MAX_W];
int H,W,K;

bool find(int y,int x){
  for(int i = x ; i < W ; i++){
    if(data[y][i] == '#'){
      return true;
    }
  }
return false;
}

void display(vector<int> vec){
  cout << "display " << endl;
  for(int i = 0 ; i < vec.size() ; i++){
    cout << vec[i] << ' ';
  }
  cout << endl;
  cout << "display end " << endl;
}

int main(){
  cin >> H >> W >> K;

  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      char c; cin >> c;
      data[i][j] = c;
    }
  }
  int now = 0;
  vector<vector<int> > res;
  for(int i = 0 ; i < H ; i++){
    vector<int>vec;
    if(!find(i,0)){
      res.push_back(vec);
      continue;
    }
    for(int j = 0 ; j < W ; j++){
      if(find(i,j)){
        now++;
        for( ; j < W ; j++){
          //cout << "j = " << j << endl;
          //cout << "now = " << now << endl;
          vec.push_back(now);
          if(data[i][j] == '#'){
            break;
          }
        }
        //cout << "#1" << endl;
        //display(vec);
      }
      else {
        for( ; j < W ; j++){
         vec.push_back(now);
        }
        //cout << "#2" << endl;
        //display(vec);
      }
    }
    //cout << "#3" << endl;
    //display(vec);
    res.push_back(vec);
  }

  vector<int> pre_vec;
  for(int i = 0 ; i < res.size() ; i++){
    if(res[i].size() > 0){
      pre_vec = res[i];
      break;
    }
  }

  //cout << "res.size() = " << res.size() << endl;
  for(int i = 0 ; i < res.size() ; i++){
    //cout << "i = " << i << " res[i].size() = " << res[i].size() << endl;
    vector<int> now_vec = res[i];
    if(now_vec.size() == 0){
      now_vec = pre_vec;
    }
    for(int j = 0 ; j < now_vec.size() ; j++){
      if(j)cout << ' ' ;
      cout << now_vec[j];
    }
    cout << endl;
    pre_vec = now_vec;
  }
  return 0;
}


Compiler output:
a.cc: In function 'bool find(int, int)':
a.cc:12:8: error: reference to 'data' is ambiguous
   12 |     if(data[y][i] == '#'){
      |        ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [301][301]'
    7 | char data[MAX_H][MAX_W];
      |      ^~~~
a.cc: In function 'int main()':
a.cc:34:7: error: reference to 'data' is ambiguous
   34 |       data[i][j] = c;
      |       ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [301][301]'
    7 | char data[MAX_H][MAX_W];
      |      ^~~~
a.cc:52:14: error: reference to 'data' is ambiguous
   52 |           if(data[i][j] == '#'){
      |              ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [301][301]'
    7 | char data[MAX_H][MAX_W];
      |      ^~~~