Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
99659 陈志轩 已知后序、中序遍历序列求前序遍历序列 C++ 通过 100 0 MS 256 KB 406 2023-08-23 14:50:09

Tests(5/5):


#include<bits/stdc++.h> using namespace std; void dfs(string mid,string end){ int len = end.size(); if (len == 0){ return ; } char root = end[len - 1]; cout<<root; int pos = mid.find(root); dfs(mid.substr(0,pos),end.substr(0,pos)); dfs(mid.substr(pos + 1,len - pos - 1),end.substr(pos,len - pos - 1)); } int main(){ string mid,end; cin>>end>>mid; dfs(mid,end); return 0; }


测评信息: