#10408. szjy_6_树_028
szjy_6_树_028
szjy_6_树_028
函数 ok 判断一组二进制串是否满足前缀编码条件。程序输出是( )。
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool ok(vector<string> code) {
sort(code.begin(), code.end());
for (int i = 0; i + 1 < (int)code.size(); ++i) {
if (code[i + 1].rfind(code[i], 0) == 0) return false;
}
return true;
}
int main() {
cout << ok({"0", "10", "110", "111"});
}
{{ select(1) }}
- -1
- 2
- 0
- 1