You need to enable JavaScript to run this app.
最新活动
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

C-Histogramwithsharedvaluesinadditionaloutput

原问题描述:给定一个数组,计算每个元素在数组中出现的次数,并使用直方图形式输出。此外,还需要输出共享同一值的元素的数量。

如果我们已经使用桶来计数每个元素出现的次数,最简单的方法是遍历桶并计算所有具有相同计数的元素个数。在此过程中,我们可以使用另一个桶以元素计数的形式跟踪每种计数出现的次数。下面是C语言的示例代码:

#include <stdio.h>
#include <stdlib.h>

#define MAX_VALUE 100

int main() {
    int n, i;
    scanf("%d", &n);

    int count[MAX_VALUE + 1] = {0};
    for (i = 0; i < n; i++) {
        int value;
        scanf("%d", &value);
        count[value]++;
    }

    int frequency[MAX_VALUE + 1] = {0};
    for (i = 0; i <= MAX_VALUE; i++) {
        if (count[i] != 0) {
            frequency[count[i]]++;
        }
    }

    int max_frequency = 0;
    for (i = 0; i <= MAX_VALUE; i++) {
        max_frequency = (frequency[i] > max_frequency) ? frequency[i] : max_frequency;
    }

    for (i = 1; i <= max_frequency; i++) {
        for (int j = 0; j <= MAX_VALUE; j++) {
            if (frequency[count[j]] >= i) {
                printf("* ");
            } else {
                printf("  ");
            }
        }
        printf("\n");
    }

    for (i = 0; i <= MAX_VALUE; i++) {
        if (count[i] != 0) {
            printf("%d ", i);
        }
    }
    printf("\n");

    for (i = 0; i <= MAX_VALUE; i++) {
        if (count[i] != 0) {
            printf("%d ", count[i]);
        }
    }
    printf("\n");

    return
本文内容通过AI工具匹配关键字智能整合而成,仅供参考,火山引擎不对内容的真实、准确或完整作任何形式的承诺。如有任何问题或意见,您可以通过联系service@volcengine.com进行反馈,火山引擎收到您的反馈后将及时答复和处理。
展开更多
面向开发者的云福利中心,ECS 60元/年,域名1元起,助力开发者快速在云上构建可靠应用

社区干货

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

C-Histogramwithsharedvaluesinadditionaloutput -优选内容

可视化建模 Open API
"outputColumns": [ { "name": "w", "type": "string", "originPrepType": "string", "originType": "string", "is_supp... "encryptMethod": 0, "additionalParamsStr": null, "jdbcConnectionString": null, "shardNum": 0, "chPartitionType": null, "clusterName...
DBT
with the connection 连接和身份验证配置所需参数:主机 端口 用户 密码 yaml bytehouse_profile: target: dev outputs: dev: type: bytehouse driver: native database schema: $DATABASE_NAME target server address host: $HOST_ADDRESS port: $PORT_NUMBER account credentials user: bytehouse password: $API_KEY additional setti...
API发布历史
2024年03月API 发布时间 变更记录 关联功能 RunInstances 2024-03-22 新增请求参数(可选): EipAddress.ReleaseWithInstance,表示创建实例时是否选择公网IP随实例释放。 Volumes.N.SnapshotId,表示使用快照创建云... 全量数据同步 ServerMigration_AdditionalSync表示服务器迁移,增量数据同步 GpuRiskDetected表示GPU运行存在风险 DescribeSystemEvents 变更请求参数:Types.N参数新增取值:ApplicationFailure表示应用异常 Dep...
聚合函数
Type is same as input column. Example sql CREATE TABLE IF NOT EXISTS test.functionAnyHeavy(id Int) ENGINE=CnchMergeTree() ORDER BY id;INSERT INTO test.functionAnyHeavy values (1),(1),(1),(2),(3);SE... plain%20text ┌─groupArray(5)(number)─┐│ [0, 1, 2, 3, 4] │└───────────────────────┘histogramCalculates an adaptive histogram. It does not guarantee precise resul...

C-Histogramwithsharedvaluesinadditionaloutput -相关内容

ByteHouse JDBC Driver

import java.sql.SQLException;import java.sql.Statement;import java.util.Properties;import javax.sql.DataSource;public class SimpleQuery { public static void main(String[] args) throws Exception {... (Connection connection) { try (Statement stmt = connection.createStatement()) { stmt.executeUpdate( "INSERT INTO inventory.orders VALUES ('54895','Apple',12)" ...

SQL Statements

Dumps the query AST.Syntax sql AST queryOutput Column Description explain The parsedASTof the statement Example sql AST SELECT 1;plain%20text Explain ParsedAST (children 1) SelectWithUnionQuery... ( `order_by_column` String)ENGINE = `CnchMergeTree`ORDER BY (`order_by_column`) step 2: drop a tableDROP TABLE example_table Insert StatementAdds data into a table. INSERT VALUESData can be inser...

地理函数

geohashDecodeDecodes any geohash-encoded string into longitude and latitude. Syntax sql geohashDecode(encoded_string)Arguments encoded_string - geohash-encoded string. Returned values longitude and... with holes (cut out sections). In this case, add polygons that define the cut out sections using additional arguments of the function. The function does not support non-simply-connected polygons. Re...

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

请求结构定义

VpcCniConfig VpcCniConfigRequest 否 VPC-CNI 网络配置。PodNetworkMode=VpcCniShared时才能配置,但非必选。 FlannelConfigRequest参数名 参数类型 是否必选 示例值 说明 PodCidrs []String 是 [... AdditionalContainerStorageEnabled Boolean 否 false 配置节点的第一块数据盘并格式化挂载作为容器镜像和日志的存储目录,取值范围: false:(默认值)关闭 true:开启 InitializeScript String 否 ZWNobyAi...

任务接口

"outputColumns": [ { "name": "w", "type": "string", "originPrepType": "string", "originType": "string", "is_supp... "encryptMethod": 0, "additionalParamsStr": null, "jdbcConnectionString": null, "shardNum": 0, "chPartitionType": null, "clusterName...

内置函数

聚合函数 NUMERIC_HISTOGRAM 统计指定列的近似直方图。 聚合函数 PERCENTILE 计算精确百分位数,适用于小数据量。 聚合函数 PERCENTILE_APPROX 计算近似百分位数,适用于大数据量。 字符串函数 ASCII 返回字符串的第一个字符的 ASCII 码。 字符串函数 CHR 将指定 ASCII 码转换成字符。 字符串函数 CONCAT 将字符串连接在一起。 字符串函数 ENCODE 将字符串按照指定编码格式编码。 字符串函数 FIND_IN_SET 在以逗号分隔的字符串中查...

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

产品体验

体验中心

云服务器特惠

云服务器
云服务器ECS新人特惠
立即抢购

白皮书

一图详解大模型
浓缩大模型架构,厘清生产和应用链路关系
立即获取

最新活动

爆款1核2G共享型服务器

首年60元,每月仅需5元,限量秒杀
立即抢购

火山引擎增长体验专区

丰富能力激励企业快速增长
查看详情

数据智能VeDI

易用的高性能大数据产品家族
了解详情

一键开启云上增长新空间

立即咨询