Language: C++

#include <iostream>
#include <queue>
#include <algorithm>

class FC{
public:
	int p[31];
	int n;
	
	bool is_over()
	{
		return p[1]==p[2] && p[2]==p[3] && p[3]==p[4] && p[4]==p[5] && p[5]==p[6] && p[6]==p[7] && p[7]==p[8] && p[8]==p[9] && p[9]==p[10] && p[10]==p[11] && p[11] == p[12] && p[12]==p[3] && p[13]==p[14] && p[14]==p[15] && p[15]==p[16] && p[16]==p[17] && p[17]==p[18] && p[18]==p[19] && p[19]==p[20] && p[20]==p[21] && p[21]==p[22] && p[22]==p[23] && p[23]==p[24] && p[24]==p[25] && p[25]==p[26] && p[26]==p[27] && p[27]==p[28] && p[28]==p[29] && p[29]==p[30] && p[30]==p[31];
	}
	void rot1()
	{
		swap(p[7],p[22]); swap(p[8],p[23]); swap(p[9],p[24]); swap(p[13] , p[18]); swap(p[10],p[12]);
	}
	void rot2()
	{
		swap(p[1],p[28]); swap(p[2],p[29]); swap(p[3],p[30]); swap(p[15] , p[16]); swap(p[21],p[19]);
	}
	void rot3()
	{
		swap(p[1],p[24]); swap(p[4],p[25]); swap(p[7],p[28]); swap(p[10] , p[21]); swap(p[16],p[18]);
	}
	void rot4()
	{
		swap(p[3],p[22]); swap(p[6],p[25]); swap(p[9],p[30]); swap(p[15] , p[13]); swap(p[12],p[19]);
	}
};

int main()
{
	int N; 
	cin>>N;
	
	for(int i=0; i<N; i++){
		FC now;
		for(int j=1; j<30; j++){
			cin>>now.p[j];
		}
		now.n=0;
		
		queue<FC> que;
		que.push(now);
		
		while(!que.empty()){
			now=que.front();
			que.pop();
			
			if(now.is_over()){
				cout<<now.n<<endl;
				break;
			}
			
			FC next1=now; next1.rot(); next1.n++; que.push(next1);
			FC next2=now; next2.rot(); next2.n++; que.push(next2);
			FC next3=now; next3.rot(); next3.n++; que.push(next3);
			FC next4=now; next4.rot(); next4.n++; que.push(next4);
		}
	}
	return 0;
}
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			

Compiler output:
a.cc: In member function 'void FC::rot1()':
a.cc:16:17: error: 'swap' was not declared in this scope
   16 |                 swap(p[7],p[22]); swap(p[8],p[23]); swap(p[9],p[24]); swap(p[13] , p[18]); swap(p[10],p[12]);
      |                 ^~~~
a.cc:16:17: note: suggested alternatives:
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_queue.h:834:5: note:   'std::swap'
  834 |     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
      |     ^~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
/usr/include/c++/14/bits/exception_ptr.h:229:5: note:   'std::__exception_ptr::swap'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
a.cc: In member function 'void FC::rot2()':
a.cc:20:17: error: 'swap' was not declared in this scope
   20 |                 swap(p[1],p[28]); swap(p[2],p[29]); swap(p[3],p[30]); swap(p[15] , p[16]); swap(p[21],p[19]);
      |                 ^~~~
a.cc:20:17: note: suggested alternatives:
/usr/include/c++/14/bits/stl_queue.h:834:5: note:   'std::swap'
  834 |     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
/usr/include/c++/14/bits/exception_ptr.h:229:5: note:   'std::__exception_ptr::swap'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
a.cc: In member function 'void FC::rot3()':
a.cc:24:17: error: 'swap' was not declared in this scope
   24 |                 swap(p[1],p[24]); swap(p[4],p[25]); swap(p[7],p[28]); swap(p[10] , p[21]); swap(p[16],p[18]);
      |                 ^~~~
a.cc:24:17: note: suggested alternatives:
/usr/include/c++/14/bits/stl_queue.h:834:5: note:   'std::swap'
  834 |     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
/usr/include/c++/14/bits/exception_ptr.h:229:5: note:   'std::__exception_ptr::swap'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
a.cc: In member function 'void FC::rot4()':
a.cc:28:17: error: 'swap' was not declared in this scope
   28 |                 swap(p[3],p[22]); swap(p[6],p[25]); swap(p[9],p[30]); swap(p[15] , p[13]); swap(p[12],p[19]);
      |                 ^~~~
a.cc:28:17: note: suggested alternatives:
/usr/include/c++/14/bits/stl_queue.h:834:5: note:   'std::swap'
  834 |     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   'std::swap'
/usr/include/c++/14/bits/exception_ptr.h:229:5: note:   'std::__exception_ptr::swap'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
a.cc: In function 'int main()':
a.cc:35:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   35 |         cin>>N;
      |         ^~~
      |         std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:44:17: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
   44 |                 queue<FC> que;
      |                 ^~~~~
      |                 std::queue
/usr/include/c++/14/bits/stl_queue.h:96:11: note: 'std::queue' declared here
   96 |     class queue
      |           ^~~~~
a.cc:44:25: error: expected primary-expression before '>' token
   44 |                 queue<FC> que;
      |                         ^
a.cc:44:27: error: 'que' was not declared in this scope
   44 |                 queue<FC> que;
      |                           ^~~
a.cc:52:33: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   52 |                                 cout<<now.n<<endl;
      |                                 ^~~~
      |                                 std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:52:46: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   52 |                                 cout<<now.n<<endl;
      |                                              ^~~~
      |                                              std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:56:45: error: 'class FC' has no member named 'rot'; did you mean 'rot1'?
   56 |                         FC next1=now; next1.rot(); next1.n++; que.push(next1);
      |                                             ^~~
      |                                             rot1
a.cc:57:45: error: 'class FC' has no member named 'rot'; did you mean 'rot1'?
   57 |                         FC next2=now; next2.rot(); next2.n++; que.push(next2);
      |                                             ^~~
      |                                             rot1
a.cc:58:45: error: 'class FC' has no member named 'rot'; did you mean 'rot1'?
   58 |                         FC next3=now; next3.rot(); next3.n++; que.push(next3);
      |                                             ^~~
      |                                             rot1
a.cc:59:45: error: 'class FC' has no member named 'rot'; did you mean 'rot1'?
   59 |                         FC next4=now; next4.rot(); next4.n++; que.push(next4);
      |                                             ^~~
      |                                             rot1