读入一篇文章到数组word中,word是char*的数组,且其空间指向inputChars数组。下面的代码生成二阶马尔科夫链,即用前两个单词来计算当前单词。
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int k=2;
const int MAXN=5000000;
char inputChars[MAXN],*word[MAXN];
int nWord=0;
bool wordncmp(char *p,char *q)//比较p和q是否有两个单词形同
{
int n=k;
while(*p==*q)
{
p++;
q++;
if(*p==0 && --n==0)
{
return true;
}
}
return false;
}
char *skip(char *p,int n)//跳过n个单词
{
while(n>0)
{
p++;
if(*p==0)
n--;
}
return ++p;
}
bool compare(char *p,char *q)
{
while(*p==*q)
{
p++;
q++;
}
return *p-*q<0;
}
int main()
{
word[0]=inputChars;
freopen("input.txt","r",stdin);
while(cin&