?? algorithm.cpp
字號(hào):
#include "stdafx.h"
#include "algorithm.h"
#include <cstdlib>
#include<ctime>
using std::iostream ;
using std::cout;
using std::rand;
using std::srand;
void algorithm::build(Prefix &prefix,istream &in )
{
string buf;
while(in>>buf)
add(prefix,buf);
}
void algorithm::add(Prefix &prefix,const string &s)
{
if(prefix.size ()==NPREF)
{
table[prefix].push_back(s);
prefix.pop_front ();
}
prefix.push_back (s);
}
void algorithm::generate(int nwords,ostream &out)
{
Prefix prefix;
for(int i=0;i<NPREF;i++)
{
add(prefix,NONWORD);
}
for(int i=0;i<nwords;i++)
{
vector<string > &suf= table[prefix];
// srand((unsigned int) time(0));
const string &w=suf[rand() % suf.size()];
if(w==NONWORD)
break;
out<<w<<" ";
prefix.pop_front ();
prefix.push_back(w);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -