hdu1251统计难题(字典树小试牛刀)
来源:互联网 发布:matlab数组写入excel 编辑:程序博客网 时间:2024/06/14 03:42
->题目猛戳这里<-
题目大意:略
题目分析:建棵字典树就ok,详情请见代码:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;char s[20];typedef struct node{ struct node *next[26]; int num;}tree;void init(tree *t){t->num = 0;for(int i = 0;i < 26;i ++)t->next[i] = NULL;}void build(tree *t,int id){ if(t->next[s[id] - 'a'] == NULL) { t->next[s[id] - 'a'] = (tree *)malloc(sizeof(tree)); init(t->next[s[id] - 'a']); t->next[s[id] - 'a']->num = 1; } else { t->next[s[id] - 'a']->num ++; } if(s[id + 1] == '\0') return; else build(t->next[s[id] - 'a'],id + 1);}int query(tree * t,int id){ if(t->next[s[id] - 'a'] == NULL) return 0; if(s[id + 1] == '\0') return t->next[s[id] - 'a']->num; return query(t->next[s[id] - 'a'],id + 1);}int main(){ tree *root = NULL; root = (struct node *)malloc(sizeof(struct node)); init(root); while(gets(s)) { //puts(s); if(strlen(s) == 0) break; build(root,0); } while(gets(s) != NULL) { int ans; ans = query(root,0); printf("%d\n",ans); } return 0;}//140MS43896K
- hdu1251统计难题(字典树小试牛刀)
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树模版)
- HDU1251 统计难题(字典树模板)
- HDU1251统计难题(字典树模板)
- HDU1251 统计难题(字典树)
- 统计难题(hdu1251,字典树)
- hdu1251 统计难题 (字典树查找)
- hdu1251统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251 统计难题(字典树)
- HDU1251-统计难题(字典树)
- hdu1251 统计难题 字典树
- 【字典树】 hdu1251 统计难题
- hdu1251 统计难题(字典树)
- Android 自定义旋转进度框(单帧)
- 绘制文字,。说明:该文字由图片充填,图片自己找
- Wiki OI 1044 拦截导弹
- 构串操作符#和合并操作符##的用法
- .编写一个Windows应用程序,由给定数据25,15,10,30,20饼图
- hdu1251统计难题(字典树小试牛刀)
- Linux开启mysql远程连接的设置步骤
- 8086 寻址方式(一)CPU和主存中的寻址方式
- Fileatream表示文件流,它能够打开和关闭文件,并对文件进行单字节的读写操作。 StreamReader和StreamWriter以文本方式对流进行读写操作。建立一个文本文件,分别使用上面两种方
- Spring事务详解
- Oracle建立索引的规则
- 文件读写
- Poj 2506 Tiling
- sicp 习题2.33