我可以使用c++中的unique命令来获取频率吗
can i use the unique command in c++ to get frequency
我想得到存储在向量中的单词的频率。我已经在谷歌上搜索了很多次我的问题,但没有去做对我有用的事情。我发现了一个网站,有人说要使用unique
命令来计算单词的频率,但我找不到任何例子来说明如何做到这一点。
使用map<string, unsigned>
创建直方图:
using std::string;
using std::map;
using std::vector;
typedef map<string, unsigned> counts_t;
// Create the histogram
counts_t histogram;
for (vector<string>::const_iterator i = vec.begin(); i != vec.end(); ++i)
++histogram[*i];
// ... and display it.
for (counts_t::const_iterator i = histogram.begin(); i != histogram.end(); ++i) {
double freq = static_cast<double>(i->second) / vec.size();
std::cout << i->first << ": " << freq << "n";
}
不使用unique,但对于单词计数来说,无论是在内存使用方面还是在其他方面,都很难击败trie或其任何衍生物;速度
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 芬威克树(BIT).找到具有给定累积频率的最小索引,单位为 O(logN)
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 在指针的帮助下,文本文件中单词的频率
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 如何使用 XAudio2 获取给定时间的频率值
- 获取给定数字集中具有相同数字频率的组数
- 我可以使用c++中的unique命令来获取频率吗
- 在获取CPU频率方面需要一些帮助
- 如何从wav文件中获取时域中的频率