c++ - 如何使用Qt计算表中值的频率
问题描述
通常在我的表上我有这些值 (0,0,80,0,0,0,80,80,80,40) 这个表被命名为 qvValues ,我想在频率表上 (5,4,1)
#include<QDebug>
#include <QList>
QList<double> frequencies;
QList<double> qvValues;
for(int i=0;i<qvValues.size();i++)
{
frequencies.append(qvValues.count( qvValues[i]));
}
qDebug() << frequencies;
解决方案
这些值来自您的示例(评论)。
#include <QMap>
#include <QList>
#include <QDebug>
int main(int argc, char *argv[])
{
QList<int> values;
QMap<int, int> frequencies;
values << 0 << 0 << 80 << 0 << 0 << 0 << 80 << 80 << 80 << 40;
int value;
foreach ( value, values )
{
if ( !frequencies.contains( value ) )
{
frequencies.insert( value, values.count( value ) );
qDebug() << "Value: " << value << " Frequency: " << values.count( value );
}
}
return 0;
}
推荐阅读
- firebase - How can I get custom querystring included in returned firebase dynamic shortlink
- dart - How can I create Page Indicator inside DefaultTabController without TabBar Widget?
- spring-boot - 为什么当休息模板抛出异常时没有调用自定义休息错误处理程序?
- python - 我将十六进制数据存储在 str 类型的列表中(例如:'0x15'),如何将列表中的 str 转换为 int 类型
- php - 通过 PHP 执行 2 个查询
- google-cloud-platform - GCP VM 无法启动或移动 TERMINATED 实例
- r - How to melt a multiple columns df with R?
- javascript - JS如何获取中心高的x/y坐标?
- shiny - shinyapps.io 上的应用程序行为
- python - 在 Python 中从 MP4 数据字节中提取波形