diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-11-01 11:51:53 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-11-01 11:51:53 +0200 |
| commit | 91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656 (patch) | |
| tree | 0b8fa3a57f5e442c8134f089e64019aba89c5b19 /codechef/ShortestPathInBinaryTrees/main.cpp | |
| parent | f2c878488b659cd19ccecc9880e042251585fdbb (diff) | |
| download | competitive-programming-91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656.tar.xz competitive-programming-91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656.zip | |
Added new problems
Diffstat (limited to 'codechef/ShortestPathInBinaryTrees/main.cpp')
| -rw-r--r-- | codechef/ShortestPathInBinaryTrees/main.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/codechef/ShortestPathInBinaryTrees/main.cpp b/codechef/ShortestPathInBinaryTrees/main.cpp new file mode 100644 index 0000000..eb5f641 --- /dev/null +++ b/codechef/ShortestPathInBinaryTrees/main.cpp @@ -0,0 +1,24 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int i, j; + cin >> i >> j; + int ans = 0; + while(i != j) { + if (j > i) { + j /= 2; + } else { + i /= 2; + } + ans++; + } + cout << ans << '\n'; + } +} |
