这两天写规模序列法预测油气储量,翻到《复杂性思考》第五章“无标度网络”,先讲的是Zipf定律。
大概意思就是自然语言中单词频数和名次之间在双对数坐标下呈线性关系,遂我自己编写了统计字符的程序。
使用了map字典
// 头文件
#ifndef LETTERSTAT_H
#define LETTERSTAT_H
#include <map>
class QChar;
class QString;
class LetterStatPrivate;
class LetterStat
{
public:
static std::map<QChar, int> getStatInfo(const QString& str);
private:
LetterStat(const QString& content);
LetterStatPrivate* m_ptr;
};
#endif // LETTERSTAT_H
// cpp
#include "LetterStat.h"
#include <QDebug>
#include <QMap>
class LetterStatPrivate : public QMap<QChar, int>
{
public:
LetterStatPrivate(){}
void statInfo()
{
qDebug() << QString("Nu