poj 2418
来源:互联网 发布:矩阵分析引论视频 编辑:程序博客网 时间:2024/06/05 10:44
#include<iostream>#include<cstdio>#include<string.h>#include<cstring>#include<string>#include<stack>using namespace std;class node{public:string ss;int total;node*l,*r;node(string _ss):ss(_ss),total(1),l(NULL),r(NULL){}}*root;typedef node* Node;char tree[40];string cmps;void Delete(Node*r);int main(){//freopen("2.txt","w",stdout);long long cnt = 0;root = NULL;Node tmp;while(scanf("%[^\n]",tree)!=EOF){++cnt;tmp = root;if(tmp == NULL){root = new node(tree);tmp = root;}else{tmp = root;cmps = (string)tree;while(true){if(cmps > tmp->ss){if(tmp->r != NULL){tmp = tmp->r;}else{tmp->r = new node(cmps);break;}}else if(cmps < tmp->ss){if(tmp->l != NULL){tmp = tmp->l;}else{tmp->l = new node(cmps);break;}}else{tmp->total++;break;}}}getchar();} //end while//中序遍历stack<Node> astack;Node p = root;while(!astack.empty()||p){if(p){astack.push(p);p = p->l;}else{p = astack.top();astack.pop();//printf("%d \n",p->total);double rate = 100.0*((double)p->total)/((double)cnt);printf("%s %.4lf\n",p->ss.c_str(),rate);p = p->r;}}Delete(&root);//cout << root << endl;return 0;}void Delete(Node*r){Node &tmp = *r;if(tmp != NULL){if(tmp->l)Delete(&tmp->l);if(tmp->r)Delete(&tmp->r);delete tmp;tmp = NULL;}}bst水题~注意cnt可能超过Int所表示的范围
0 0
- POJ 2418
- poj 2418
- poj-2418
- poj 2418
- poj 2418
- poj-2418
- POJ 2418 Java
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418 Hardwood Species
- poj 2418(二叉排序树)
- poj 2418(TreeMap)
- POJ 2418 Hardwood Species
- poj 2418 Trie
- POJ 2418 Hardwood Species
- poj 2418Hardwood Species
- android 软电话 开发包-JNI 封装 SIP 协议,可进行二次开发应用于VOIP
- ADCD相关介绍
- 其它常用API__【System】【Runntime】【Date】【Math】等
- Android自定义控件
- doxygen相关资料
- poj 2418
- 【USACO 2013 February Gold】分割农场
- DIV+CSS圆角边框
- 说说真实的心里话吧
- java interface 介绍
- [iOS]解决键盘弹出时挡住输入框的问题
- 求大神赐教严重: Error configuring application listener of class org.springframework.web.context.ContextLoad
- Leetcode: Search Insert Position
- 黑马程序员—静态与非静态、构造函数