二叉排序树
来源:互联网 发布:炫踪网络上市计划启动 编辑:程序博客网 时间:2024/06/06 02:25
此题高能预警
题目链接
#include<iostream>#include<algorithm>#include<string>#include<cstring>using namespace std;typedef struct node{ char data; node *l; node *r;}Tree;Tree *creat(char key, Tree *root){ if(root==NULL) { root=new Tree; root->l=NULL; root->r=NULL; root->data=key; } else { if(key<root->data) root->l=creat(key, root->l); else root->r=creat(key, root->r); } return root;}int f=0;char a[1000];void fistree(Tree *root){ if(root) { a[f++]=root->data; fistree(root->l); fistree(root->r); }}char b[1000];int l=0;void lastree(Tree *root){ if(root) { lastree(root->l); lastree(root->r); b[l++]=root->data; }}int main(){ ios::sync_with_stdio(false); int n; char x[100]; Tree *root; while(cin>>n) { if(n==0) break; cin>>x; int len=strlen(x); root=NULL; for(int i=0;i<len;i++) { root=creat(x[i], root); } fistree(root); lastree(root); a[f]='\0'; b[l]='\0'; while(n--) { char c[100]; cin>>c; if(strcmp(a,c)==0) cout<<"YES"<<endl; else if(strcmp(b, c)==0) cout<<"YES"<<endl; else if(strcmp(x, c)==0) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0;}
0 0
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- Android4.3 蓝牙BLE初步
- Openwrt下设置端口映射 DMZ 访问控制
- spring模板模式与callback
- Shell 字符串处理、获取文件名和后缀名
- vector<bool>效率问题的原因和替代方法
- 二叉排序树
- hdu2108Shape of HDU 计算几何
- IOS NSInvocation应用与理解
- Qt的5种常用布局搭建
- Lua继承的实现(__index元方法)
- Java反射简介
- 修复sublime text3在ubuntu下无法中文输入
- 程序员如何做到年薪 50 万?--知乎整理
- AngularJs的初步使用