Language: C++

#include<iostream>
#include<vector>
using namespace std;
vector<char> vec;
char tab[20][20];
int ans,pre,dx[]={0,0,1,-1},dy[]={1,-1,0,0},plus,used[20][20];
void are1(int y,int x,char c){
	pre++;
	used[y][x]=1;
	int ny,nx;
	for(int i=0;i<4;i++){
		ny=dy[i]+y;nx=dx[i]+x;
		if(ny>=0&&ny<12&&nx>=0&&nx<6){
		if(tab[ny][nx]==c&&used[ny][nx]==0)
			are1(ny,nx,c);
		}
	}
}
void are2(int y,int x,char c){
	int ny,nx;
	tab[y][x]='.';
	for(int i=0;i<4;i++){
		ny=dy[i]+y;nx=dx[i]+x;
		if(ny>=0&&ny<12&&nx>=0&&nx<6){
			if(tab[ny][nx]==c)
				are2(ny,nx,c);
			else if(tab[ny][nx]=='O')
				tab[ny][nx]='.';
		}
	}
}
void rensa(){
	memset(used,0,sizeof(used));
	for(int i=0;i<12;i++)
	for(int j=0;j<6;j++){
		if(tab[i][j]!='O'&&tab[i][j]!='.'){
			pre=0;
			are1(i,j,tab[i][j]);
			if(pre>=4){
				are2(i,j,tab[i][j]);
				plus++;
			}
		}
	}
}
void liset(){
	int k;
	for(int i=0;i<6;i++){
		k=0;
		for(int j=11;j>=0;j--){
			if(tab[j][i]!='.')
			vec.push_back(tab[j][i]);
		}
		for(int j=11;(int)11-j<(int)vec.size();j--)
			tab[j][i]=vec[k++];
		for(int j=(int)11-vec.size();j>=0;j--)
			tab[j][i]='.';
		vec.clear();
	}
}
void solve(){
	do{
		plus=0;
		rensa();
		if(plus){
		liset();
		ans++;
		}
	}while(plus);
}
int main(){
	int n;
	cin>>n;
	while(n-->0){
		ans=0;
		for(int i=0;i<12;i++)
		cin>>tab[i];
		solve();
		cout<<ans<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void rensa()':
a.cc:33:9: error: 'memset' was not declared in this scope
   33 |         memset(used,0,sizeof(used));
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<vector>
  +++ |+#include <cstring>
    3 | using namespace std;
a.cc:41:33: error: reference to 'plus' is ambiguous
   41 |                                 plus++;
      |                                 ^~~~
In file included from /usr/include/c++/14/string:49,
                 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/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:6:45: note:                 'int plus'
    6 | int ans,pre,dx[]={0,0,1,-1},dy[]={1,-1,0,0},plus,used[20][20];
      |                                             ^~~~
a.cc: In function 'void solve()':
a.cc:63:17: error: reference to 'plus' is ambiguous
   63 |                 plus=0;
      |                 ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:6:45: note:                 'int plus'
    6 | int ans,pre,dx[]={0,0,1,-1},dy[]={1,-1,0,0},plus,used[20][20];
      |                                             ^~~~
a.cc:65:20: error: reference to 'plus' is ambiguous
   65 |                 if(plus){
      |                    ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:6:45: note:                 'int plus'
    6 | int ans,pre,dx[]={0,0,1,-1},dy[]={1,-1,0,0},plus,used[20][20];
      |                                             ^~~~
a.cc:69:16: error: reference to 'plus' is ambiguous
   69 |         }while(plus);
      |                ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:6:45: note:                 'int plus'
    6 | int ans,pre,dx[]={0,0,1,-1},dy[]={1,-1,0,0},plus,used[20][20];
      |                                             ^~~~