Kitty cat gene code \operatorname{Kitty cat gene code} K I T T Y cats group by encoding code
Title link: luogu P2562 \operatorname{luogu\ P2562}luogu P2562
topic
You can choose to study basic biological genetics. The professor tells everyone that the length of the kitty cat on Super Samuel is 2 22 to the power of a positive integer), all are composed of two different gene units. These two different gene units are recorded as0 00 and1 11 , so the Kitty cat gene can be written as a 01 string expression.
In order to facilitate analysis and reduce the amount of data storage, the professor invented the ABC coding rule. The coding rule is to continuously
rewrite the expression of Kitty cat gene 01 string until it is finally rewritten into a symbol string containing only the characters "A", "B", and "C".
Please write a program to help Coco find the ABC code of Kitty cat gene to assist professors in scientific research.
enter
The file contains a 01 string expression of Kitty cat gene in one line.
Output
Output the ABC code of this Kitty cat gene in one line.
Sample input 1
00
Sample output 1
A
Sample input 2
01001011
Sample output 2
CCCABACCBAB
data range
Given 01 string length L en ≤ 256 Len\leq 256L e n≤256
Ideas
This question is actually very similar to the FBI tree I did before , with only a few differences:
- Even if it is all 0 0 in the FBI tree0 or all1 11 string, must continue to recurse, but this is not used
- FBI tree post-order traversal, this is pre-order traversal
- FBI tree gives nnn , and this one does not
Code
#include<cstdio>
#include<cstring>
using namespace std;
char a[1051];
void work(int l, int r) {
int check = a[l] - '0';
for (int i = l + 1; i <= r; i++)
if ((a[i] - '0') != check) {
check = -1;
break;
}
if (check == -1) {
printf("C");
if (l < r) {
int mid = (l + r) >> 1;
work(l, mid);
work(mid + 1, r);
}
}
else if (check == 0) printf("A");
else printf("B");
}
int main() {
scanf("%s", &a);
work(0, strlen(a) - 1);
return 0;
}