Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
本人小白,用map1485ms,自己写的BST1282ms~#include<iostream> using namespace std; struct BTree { char value[35]; int num; struct BTree *lchild; struct BTree *rchild; }; void insert_node(BTree* &root,char *s1) { if(root==NULL) { root=new BTree; strcpy(root->value,s1); root->lchild=NULL; root->rchild=NULL; root->num=1; return ; } if( strcmp(root->value,s1) ==0 ) { root->num++; return ; } if(strcmp(root->value,s1)>0) { insert_node(root->lchild,s1); } else insert_node(root->rchild,s1); } void print(BTree *root,double total) { if(root==NULL) return ; print(root->lchild,total); cout<<root->value<<" "; printf("%.4lf\n",(double)root->num/total *100); print(root->rchild,total); } int main() { char s1[35]; BTree * root=NULL; double total=0; while(gets(s1)) { insert_node(root,s1); total++; //cout<<s1<<endl; } print(root,total); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator