POJ 2418 Hardwood Species
来源:互联网 发布:淘宝买家账号信誉查询 编辑:程序博客网 时间:2024/04/30 13:02
是二叉查找树入门
//============================================================================
// Name : hello.cpp// Author : key
// Version : 8
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define NUM_INF 0x7FFFFFFF
int sum;
struct Node{
char str[100];
int num;
Node* lNode;
Node* rNode;
Node(char* s)
{
lNode = rNode = NULL;
num = 1;
strcpy(str,s);
}
}*root;
Node* My_insert(Node* root_from,char* s)
{
if(NULL == root_from)
{
root_from = new Node(s);
return root_from;
}
int temp = strcmp(root_from->str,s);
if(temp==0)
{
(*root_from).num++;
return root_from;
}
if(temp > 0)
{
root_from->lNode = My_insert(root_from->lNode,s);
return root_from;
}
root_from->rNode = My_insert(root_from->rNode,s);
return root_from;
}
void dfs(Node* root_from)
{
if(NULL == root_from)
return;
dfs(root_from->lNode);
printf("%s %.4f\n", root_from->str , (*root_from).num*(100.0)/sum);
dfs(root_from->rNode);
}
int main()
{
char str_in[100];
sum = 0;
root = NULL;
while(gets(str_in))
{
root = My_insert(root,str_in);
sum++;
}
dfs(root);
return 0;
}
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418 Hardwood Species
- poj 2418 Hardwood Species
- poj 2418 Hardwood Species
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species
- 启动Apache
- POJ 1702 Eva's Balance
- 关于android安装sdk时找不到jdk的解决办法
- 一个简单的串口过滤驱动
- POJ 2021 Relative Relatives
- POJ 2418 Hardwood Species
- 关闭Aphache和重启Apache
- 嵌入式C笔试总结(长期更新)
- 优化资源
- POJ 1018 Communication System
- POJ 1220 NUMBER BASE CONVERSION
- POJ1287 Networking
- POJ 1466 Girls and Boys
- POJ 1496 1850