This question is NOI Anhui province topics, but the difficulty is not so difficult.
This question is a string of recursive problem, there are a lot of chiefs with tree line to write (I also want to learn the tree line, lowbit blow). Title means all the same the output B or A, different from the divided two sub-strings of the same length, and outputs C. I see this will be very easy to think of recursive plus two points, but how to write the above function it? I suddenly wanted to retreat, and then come strategy: enumeration substring, if there are different recursively binary output C, until the same outputs A, B.
1. Avoid low error, eg.string s [], (mid + 1, left) ,, would delay a lot of time to debug
2. The skilled use of recursive half
Code
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #define N 100001 using namespace std; string s;//! bool flag; void work(int left,int right){ flag=true; int mid=(left+right)/2; for(int i=left+1;i<=right;i++){ if(s[i]!=s[i-1]){ flag=false; break; } } if(flag==false){ cout<<"C"; work(left,mid); work(mid+1,right);//! return; } if(flag==true){ if(s[left]=='0') cout<<"A"; else if(s[left]=='1') cout<<"B"; } return; } int main(){ cin>>s; int len=s.length(); work(0,len-1);//! return 0; }