当时的想法就是每次对他进行对半分, 直到分到剩一个字符时, 到底
在这之前重复对半分, 递归, 现在献上代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 void FBI(string in, int len) { 5 if (len > 1) { 6 string in1, in2; 7 in1 = in.substr(0, in.size() / 2); 8 in2 = in.substr(in.size() / 2, in.size() / 2); 9 FBI(in1, in1.size()); 10 FBI(in2, in2.size()); 11 } 12 13 if (in.find("1") != in.npos && in.find("0") != in.npos) cout << 'F'; 14 else if (in.find("1") != in.npos) cout << 'I'; 15 else cout << 'B'; 16 } 17 18 int main(void) { 19 int n; 20 string in; 21 cin >> n >> in; 22 FBI(in, in.size()); 23 24 return 0; 25 }