codevs1094FBI树80

来源:互联网 发布:知远战略与防务论坛 编辑:程序博客网 时间:2024/05/16 06:42
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>struct Node{char *p_data;int  m_len;Node *p_left;Node *p_right;};void PrintNode(Node *pNode){int len = pNode->m_len;int sum = 0;while (len){sum += pNode->p_data[len - 1] - 48;--len;}if (sum == pNode->m_len)printf ("I");else if (sum == 0)printf ("B");elseprintf ("F");}Node* BuildTree(char* str, int len){Node *pNode = (Node*)malloc(sizeof(Node));pNode->m_len = len;pNode->p_data = str;if (len >= 2){pNode->p_left = BuildTree(str, len / 2);pNode->p_right = BuildTree(str + len / 2, len / 2);}PrintNode(pNode);return pNode;}int main (){int n;scanf("%d", &n);scanf("%*[^\n]");scanf("%*c");char buf[100];scanf ("%s", buf);if (pow(2, n) == (unsigned int)strlen(buf)){BuildTree(buf, strlen(buf));printf("\n");}return 0;}
0 0
原创粉丝点击