OJ-Problems-Source/HDOJ/4260_autoAC.cpp
2016-09-04 15:25:29 +08:00

20 lines
376 B
C++

#include<iostream>
#include<string>
using namespace std;
string s;
long long cal(long long x,char goal)
{
for(long long i=x;i>=0;i--)
if(s[i]!=goal) return cal(i-1,'A'^'B'^'C'^goal^s[i])+(1LL<<i);
return 0;
}
int main()
{
while(cin>>s,s!="X")
{
long long ans=cal(s.length()-1,'B');
cout<<ans<<endl;
}
return 0;
}