栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1899 Hardwood Species

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1899 Hardwood Species

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#define mem(a , b) memset(a , b , sizeof(a) )using namespace std ;const int MAXN = 3e5 + 5 ;char A[50] ;int vis[MAXN] ; int cnt ;  int sum ;  struct Tnode{    int count ;     char f ;      int xu ;      Tnode * next[256] ;     Tnode()    {        count = 0 ;        f = 0 ;        xu = 0 ;        mem(next , 0) ;    }} ;char s[50] ;void inse(char * str , Tnode * root){    Tnode * p = root ;    int id ;    while (*str)    {        id = *str - '' ;        if(p -> next[id] == 0)        { p -> next[id] = new Tnode ; p -> next[id] -> xu = ++ cnt ; p -> next[id] -> f = *str ;        }        p = p -> next[id] ;        ++ str ;    }    p -> count ++ ;}double ans ;void print(int deep , Tnode * p) {    int i ;    for(i = 0 ; i < 256; i ++ )    {        if(p -> next[i] != NULL)        { int tmp = p -> next[i] -> xu ; A[deep] = p -> next[i] -> f ; if(p -> next[i] -> count > 0 && !vis[tmp]) {     vis[tmp] = 1 ;     ans = p -> next[i] -> count * 100.0 / sum * 1,0;     int j ;     for(j = 0 ; j <= deep ; j ++)     {         printf("%c" , A[j]) ;     }     printf(" %.4fn" ,ans) ; } print(deep + 1 , p -> next[i]) ;        }    }}int main(){    bool flag = false ;    while (gets(s))    {        if(flag)          printf("n") ;        else        flag = true ;        cnt = 0 ;        sum = 0 ;        Tnode * root = new Tnode ;        memset(vis , 0 , sizeof(vis)) ;        inse(s , root) ;        sum ++ ;        while (gets(s) && strlen(s))        { inse(s , root) ; sum ++ ;        }        print(0 , root) ;    }    return 0 ;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378072.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号