⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 neighbor.cpp

📁 一个类似STL的自动机的源代码库
💻 CPP
字号:
#include <iostream>
#include <stream.h>
#include <language.h>
#include <neighbor.h>
#include <ccopy.h>
#include <cursor.h>
#include <dfa.h>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <unistd.h>

using namespace std;

void usage(const char* exe)
{
  cerr << "Usage: " << exe << " [-vwua] word distance" << endl;
  cerr << "       -v\tverbose mode" << endl;
  cerr << "       -w\toutput words" << endl;
  cerr << "       -a\toutput the DFA (default)" << endl;
  cerr << "       distance is a positive integer" << endl;
  exit(1);
}

int main(int argc, char** argv)
{
  typedef clone_cursor<plain> input_cursor;
  typedef DFA_bin<plain> dfa_type;

  bool verbose = false;
  bool words = false;
  const char* exe = argv[0];

  for(int c; (c = getopt(argc, argv, "vwa")) != EOF;)
    switch(c) {
    case 'v' : verbose = true; break;
    case 'w' : words = true; break;
    case 'a' : words = false; break;
    default : usage(exe);
    }

  if (optind >= argc) usage(exe);
  const char* word = argv[optind];
  if (++optind == argc) usage(exe);
  int d = atoi(argv[optind]);
  if (d < 0) usage(exe);

// deprecated:  verbose_first(verbose, argc, argv);

  dfa_type dfa;
  dfa.initial(clone(dfa, input_cursor(cin)));

  if (words) 
    language(cout, dfirstc(neighborc(forwardc(dfa), word, d)));
  else {
    DFA_stream out(cout);
    clone(out, dfirstc(neighborc(forwardc(dfa), word, d)));
  }

// deprecated:  verbose_last(verbose);
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -