HDU 1251 统计难题
来源:互联网 发布:华策影视 知乎 编辑:程序博客网 时间:2024/06/05 20:08
PS: 每每学到一个知识点,要多多练习知道非常熟悉,信手拈来, 以后多多练习一下强大的指针操作。
此题目开内存蛮大的。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct Trie { Trie* next[26]; int num;};//Accepted125178MS43796K1182 BC++AchiberTrie* root;void Insert(char *str) { Trie* now = root; int len = strlen(str); for(int i = 0; i < len; i++) { int id = str[i]-'a'; if(now->next[id]==NULL) { Trie* p = new Trie; p->num = 0; memset(p->next, NULL, sizeof(p->next)); now->next[id] = p; } now = now->next[id]; now->num++; }}int query(char* str) { Trie* now = root; int counter = 0; int len = strlen(str); for(int i = 0; i < len; i++) { int id = str[i]-'a'; if(now->next[id]==NULL) { return 0; } else { now = now->next[id]; counter = now->num; } } return counter;}int main(){ root = new Trie; memset(root->next, NULL, sizeof(root->next)); char str[20]; while(gets(str) && str[0]) Insert(str); while(gets(str)) { int res = query(str); printf("%d\n", res); } return 0;}
0 0
- HDU 1251 统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- HDU 1251:统计难题
- HDU 1251 统计难题
- Hdu-1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- HDU-1251-统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- hdu 1251统计难题
- hdu 1251 统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- mysql导入sql文件
- 一些比较好的知识点学习网址
- Java获取当前的日期和时间
- 《征服C指针》第一章重点小结
- 数字统计---解题思路
- HDU 1251 统计难题
- Android回调机制(全面深入学习一)
- Cocos2D-x游戏开发之十九:瓦块地图之碰撞检测
- OLTP和OLAP的区别
- 如何定义和引用shell中的变量
- [连载]C#程序设计(07)--- C#核心编程-5 --- 数组和字符串
- 10055 - Hashmat the Brave Warrior
- 四舍五入算法、五舍六入、六舍七入、七舍八入。。。。。。。
- win 7c盘下不能粘贴除开文件夹外的其他文件