vim搜索过字符串,打开其他文件也会高亮显示该字符串的解决办法
2016-05-02 23:15
330 查看
这是字典树的入门题,很经典,也很容易,代码比较简单易懂,所以我就不解释了。不会字典树的同学请先上网搜索相关知识~~~
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2011 panyanyany All rights reserved. URL : http://acm.hdu.edu.cn/showproblem.php?pid=1251 Name : 统计难题 Date : Thursday, May 5, 2011 Time Stage : 2 hours around Result: 3910551 2011-05-05 01:45:27 Accepted 1251 93MS 43784K 1423 B C++ pyy Test Data: Review: 初级题目,果然一次就AC了…… //----------------------------------------------------------------------------*/ #include <iostream> #include <conio.h> #include <stdio.h> #include <string.h> using namespace std; struct node { int cnt; node *childs[26]; node() { cnt = 0; memset(childs, 0, sizeof(childs)); } }; node *root = new node; int i, j, k, index; node *current, *newnode; void insert( char * str ) { current = root; for( i = 0; str[i] != '/0'; ++i ) { index = str[i] - 'a'; if( current->childs[index] != NULL ) { current = current->childs[index]; ++current->cnt; } else { newnode = new node; ++newnode->cnt; current->childs[index] = newnode; current = newnode; } } } int is_find( char *str ) { current = root; for( i = 0; str[i] != '/0'; ++i ) { index = str[i] - 'a'; if( current->childs[index] == NULL ) return 0; current = current->childs[index]; } return current->cnt; } int main() { char str[20]; while( gets(str), strcmp(str, "") ) insert( str ); while( gets(str) != NULL ) printf( "%d/n", is_find(str) ); return 0; }
相关文章推荐
- 通过案例对spark streaming透彻理解三板斧之一
- 新书到手 TRANSACTION PROCESSING:CONCEPTS AND TECHNIQUES
- 关于启明星系统(OA系统,预定系统,请假系统等)安全性的说明
- Java并发实现一(并发的实现之Thread和Runnable的区别)
- 高吞吐量的分布式发布订阅消息系统Kafka-- 管理工具 Kafka Manager
- 图片嵌入隐藏-大容量的信息隐藏算法
- A Tour of Golang (二)
- bzoj 1101: [POI2007]Zap
- 【裸奔吧linux】netstat: 显示网络连接,路由表,接口统计信息,多播成员
- Precision,Recall和F1
- java对redis的操作
- SDUT 2168 Mathmen(贪心)
- linux 中 alias 命令用法
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-B. Little Artem and Grasshopper(模拟)
- 完全卸载mysql数据库
- leetcode_096 Unique Binary Search Trees
- 宽字符和字符
- SQL语句命令
- OC里面的类类型
- 10周机电大作业设计