第二个点RE了,搞不明白为什么,求助各位大佬
查看原帖
第二个点RE了,搞不明白为什么,求助各位大佬
592342
WA_automat楼主2022/4/21 15:22
#include<iostream>
#include<cstdlib>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

char choose(string s, int start, int end) {
	if (start == end) {
		if (s[start] == '0')
			return 'B';
		if (s[start] == '1')
			return 'I';
	}
	for (int i = start; i < end; i++)
		if (s[i] != s[i + 1])
			return 'F';
	if (s[start] == '0')
		return 'B';
	else if (s[start] == '1')
		return 'I';
}

void CreateTree(char* FBI, int n, string s, int start, int end) {
	if (start == end)
		FBI[n] = choose(s, start, end);
	if (n < pow(2, s.size())) {
		FBI[n] = choose(s, start, end);
		if (start != end) {
			CreateTree(FBI, 2 * n + 1, s, start, (start + end) / 2);
			CreateTree(FBI, 2 * n + 2, s, (start + end) / 2 + 1, end);
		}
	}
}

void show(char* FBI, int n, int num) {
	if (n < num) {
		show(FBI, 2 * n + 1, num);
		show(FBI, 2 * n + 2, num);
		cout << FBI[n];
	}
}

int main(void) {
	int n;
	string s;
	cin >> n;
	char FBI[1025];
	cin >> s;
	CreateTree(FBI, 0, s, 0, s.size() - 1);
	show(FBI, 0, pow(2, n + 1) - 1);
	return 0;
}

2022/4/21 15:22
加载中...