Language: C++

#include<iostream>
#include<cstdio>
#include<string>

using namespace std;
char str[1000001];
int num[100001];
int ans;
int size;
int step(int l,int r,int w){
	int res=0;
	int a;
	for(a=1;a<=size;a++){
		if(num[a]%3==1){
			if(w==0){
				if(l==1)r=1,w=1;
				else res++,l=1,w=0;
			}else l=1,w=0;
		}
		if(num[a]%3==2){
			if(w==0){
				if(l==3)res++,l=2,w=1;
				else r=2,w=1;
			}else{
				if(r==1)res++,w=1,r=2;
				else l=2,w=0;
			}
		}
		if(num[a]%3==0){
			if(w==1){
				if(r==3)l=3,w=0;
				else res++,r=3,w=1;
			}else r=3,w=1;
		}
	}
	return res;
}

int main(void){
	int a;
	while(1){
		for(a=0;a<=100000;a++)str[a]='\0',num[a]=0;
		cin >> str;
		if(str[0]=='#')break;
		size=strlen(str);
		for(a = 0; a <size; a++) {
			num[a]=char(str[a])-'0';
		}
		ans=min(step(str[a]%3,0,0),step(0,str[a]%3,1));
		cout << ans << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int step(int, int, int)':
a.cc:13:20: error: reference to 'size' is ambiguous
   13 |         for(a=1;a<=size;a++){
      |                    ^~~~
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:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~
a.cc: In function 'int main()':
a.cc:45:17: error: reference to 'size' is ambiguous
   45 |                 size=strlen(str);
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~
a.cc:45:22: error: 'strlen' was not declared in this scope
   45 |                 size=strlen(str);
      |                      ^~~~~~
a.cc:3:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<cstdio>
  +++ |+#include <cstring>
    3 | #include<string>
a.cc:46:31: error: reference to 'size' is ambiguous
   46 |                 for(a = 0; a <size; a++) {
      |                               ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~