求助,谁可以告我一段连续的数字怎么用数组分开存储
查看原帖
求助,谁可以告我一段连续的数字怎么用数组分开存储
521302
landernal楼主2022/2/26 23:38

就这道题,10001011变成1 0 0 0 1 0 1 1,怎么存啊,就差一点

#include <iostream>
#include <cmath>
using namespace std;
int x, n, a[1026], len;
char tr[1026];
void fbi(int begin, int end, int j){
    if(j > pow(2, (n + 1)) - 1) {
        return;
    }
    int sum = 0;
    for(int i = begin; i <= end; i++) {
        sum = sum + a[i];
    }
    if(sum == 0) {
        tr[j] = 'B';
    }else if(sum == end - begin + 1) {
        tr[j] = 'I';
    }else{
        tr[j] = 'F';
    }
    fbi(begin, end - (end - begin + 1) / 2, j * 2);
    fbi((end - begin + 1) / 2 + begin, end, j * 2 + 1);
}
void putorder(int j) {
    if(j > pow(2, (n + 1)) - 1) {
        return;
    }else{
        putorder(j * 2);
        putorder(j * 2 + 1);
        cout << tr[j];
    }
}
int main(){
    cin >> n;
    len = pow(2, n);
    for(int i = 1; i <= len; i++) {
        cin >> a[i];
    }
    if(n == 0) {
        if(a[1] == 1) {
            cout << "I" << endl;
        }else{
            cout << "B" << endl;
        }
        return 0;
    }
    fbi(1, len, 1);
    putorder(1);
    return 0;
}

2022/2/26 23:38
加载中...