题解 | #二叉树#
二叉树
https://www.nowcoder.com/practice/5b80ab166efa4551844657603227caeb
#include<cstdio>
#include<vector>
using namespace std;
int main(){
long long x, y;
while (scanf("%lld %lld", &x, &y) != EOF){
vector<int>vec1;
vector<int>vec2;
vec1.push_back(x);
vec2.push_back(y);
while (x != 1){
int j = x / 2;;
vec1.push_back(j);
x = x / 2;
}
while (y != 1){
int j = y / 2;;
vec2.push_back(j);
y = y / 2;
}
int h = 0;
for (int i = 0; i <vec1.size(); i++){
if (1 == h){
break;
}
else{
for (int k = 0; k <vec2.size(); k++){
if (vec1[i] == vec2[k] && h == 0){
printf("%d\n", vec1[i]);
h = 1;
break;
}
}
}
}
}
}
