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

📄 spellcheck.cpp

📁 这是清华出的这本经典的数据结构第三版上的随书例子。希望对大家有用。
💻 CPP
字号:
#include <iostream>#include <fstream>#include <cstdlib>#include <cstring>#include <cctype>using namespace std;#include "trie.h"char* strupr(char *s) {    char *ss;    for (ss = s; *s = toupper(*s); s++);    return ss;}int main(int argc, char* argv[])  {    char fileName[25], s[80], ch;    int i, lineNum = 1;    ifstream dictionary("dictionary");    if (dictionary.fail()) {       cerr << "Cannot open 'dictionary'\n";       exit(-1);    }    dictionary >> s;    Trie trie(strupr(s));   // initialize root;    while (dictionary >> s) // initialize trie;        trie.insert(strupr(s));    trie.printTrie();    if (argc != 2) {         cout << "Enter a file name: ";         cin  >> fileName;    }    else strcpy(fileName,argv[1]);    ifstream textFile(fileName);    if (textFile.fail()) {       cout << "Cannot open " << fileName << endl;       exit(-1);    }    cout << "Misspelled words:\n";    textFile.get(ch);    while (!textFile.eof()) {        while (true)             if (!textFile.eof() && !isalpha(ch)) { // skip non-letters                  if (ch == '\n')                        lineNum++;                  textFile.get(ch);             }             else break;        if (textFile.eof())       // spaces at the end of textFile;             break;        for (i = 0; !textFile.eof() && isalpha(ch); i++) {             s[i] = toupper(ch);             textFile.get(ch);        }        s[i] = '\0';        if (!trie.wordFound(s))             cout << s << " on line " << lineNum << endl;    }    dictionary.close();    textFile.close();    return 0;}

⌨️ 快捷键说明

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