ahocorasick.cpp
来自「一个类似STL的自动机的源代码库」· C++ 代码 · 共 47 行
CPP
47 行
#include <astl.h>#include <aho_corasick.h>#include <tools.h>#include <lazy.h>#include <match.h>#include <string>#include <iostream>#include <cstdio>#include <iterator>#include <algorithm>using namespace std;const string USAGE = "[-nl] file";const string DESCRIPTION = "search stdin for the set of words read from file\\n -nl\tno lazy construction optimization";int main(int argc, char **argv){ config c(argc, argv, 2, "", USAGE, DESCRIPTION); aho_corasick_cursor<plain> ac(c.aux_input); /// aho_corasick_cursor<plain> ac(istream_iterator<string>(aux_input), /// istream_iterator<string>()); ostream_iterator<char> out(cout); c.aux_input.close(); frandom_iterator<> first(stdin), last, match; if (find(c.options.begin(), c.options.end(), string("-nl")) == c.options.end()) { lazy_cursor_tag<aho_corasick_cursor<plain> > e = lazyc_tag(ac); for(; first != last; first = match) { match = first_match(first, last, e); if (match == first) break; // no match + EOF copy(match - e.src_tag().length(), match, out); } } else for(; first != last; first = match) { match = first_match(first, last, ac); if (match == first) break; // no match + EOF copy(match - ac.src_tag().length(), match, out); } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?