BUUCTF-LeftOrRight
题目描述:
Left?Middle?No,I want right!(flag is right?!)
题目下载
给了一个打不开的图片,用notepad打开发现首位有奇怪的十六进制数,选中转换为ascii,上半部分是f09e54c1bad2x38mvyg7wzlsuhkijnop,下半部分是905e4c1fax328mdyvg7wbsuhklijznop。涉及到二叉树的遍历,题里提示左和中,就是先序和中序。
ESE师傅的脚本如下:
#include <iostream> #include <fstream> #include <string> #include <cstring> using namespace std; struct TreeNode { struct TreeNode* left; struct TreeNode* right; char elem; }; void BinaryTreeFromOrderings(char* inorder, char* preorder, int length) { if (length == 0) { //cout<<"invalid length"; return; } TreeNode* node = new TreeNode;//Noice that [new] should be written out. node->elem = *preorder; int rootIndex = 0; for (; rootIndex < length; rootIndex++) { if (inorder[rootIndex] == *preorder) break; } //Left BinaryTreeFromOrderings(inorder, preorder + 1, rootIndex); //Right BinaryTreeFromOrderings(inorder + rootIndex + 1, preorder + rootIndex + 1, length - (rootIndex + 1)); cout << node->elem; return; } int main(int argc, char* argv[]) { printf("You know the preorder and the middle order, can you find out the post order!\n"); char* pr = "f09e54c1bad2x38mvyg7wzlsuhkijnop"; char* mid = "905e4c1fax328mdyvg7wbsuhklijznop"; int len = strlen(mid); BinaryTreeFromOrderings(mid, pr, len); printf("\n"); return 0; }