当前位置:网站首页>L1-003 个位数统计
L1-003 个位数统计
2022-07-21 03:22:00 【Alter_r】
原题
给定一个 k 位整数 N=dk−110k−1+⋯+d1101+d0 (0≤di≤9, i=0,⋯,k−1, dk−1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定 N=100311,则有 2 个 0,3 个 1,和 1 个 3。
输入格式:
每个输入包含 1 个测试用例,即一个不超过 1000 位的正整数 N。
输出格式:
对 N 中每一种不同的个位数字,以 D:M
的格式在一行中输出该位数字 D
及其在 N 中出现的次数 M
。要求按 D
的升序输出。
输入样例:
100311
输出样例:
0:2
1:3
3:1
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[1010];//单字符数组s
int a[10]={0};//初始化a数组中全为0,用于统计各个数位的出现次数
int t = 0;
scanf("%s",s);
for(int i = 0; i < strlen(s); i++)//strlen(s)是数组s的长度
{
t = s[i] - '0';//S[i] - '0'变为整数
a[t]++;
}
for(int i = 0; i < 10; i++)
{
if(a[i] != 0)
printf("%d:%d\n",i,a[i]);//a的下标i是出现的数字,a[i] 为出现的次数
}
return 0;
}
边栏推荐
- 软件测试面试题:您认为在测试人员同开发人员的沟通过程中,如何提高沟通的效率和改善沟通的效果?维持测试人员同开发团队中其他成员良好的人际关系的关键是什么?
- KingbaseES V8R6有什么办法,默认不读取sys_catalog下的系统视图?
- [QT入门篇]窗口类的应用
- 分布式.高性能
- Force uninstall of additional domain controllers
- [QT入门篇]定时器QTimer类
- The first lesson of programmers is "Hello word". Do you know the first lesson of network engineering?
- [qt beginner] timer qtimer class
- 2022 software testing skills jmeter+ant+jenkins continuous integration and test report generation tutorial
- C language introduction practice (10): module taking problem
猜你喜欢
FTP服務配置
MYSQL09_精讲数据库数据类型
Naixue's tea layout: how to transform the traditional brand of yuancosmos into yuancosmos marketing
NFS服务配置
hcip第二天实验
Create high-performance applications and continuously optimize the user experience
ThreadLocal
JMeter learning notes 003-csv parameterization of JMeter
Translation and interpretation of the paper: anytime bottom up rule learning for knowledge graph completion [anyburr]
Ardunio development - I2C protocol communication - control 2x16lcd
随机推荐
软件测试面试题:在您以往的工作中,一条软件缺陷(或者叫Bug)记录都包含了哪些内容?如何提交高质量的软件缺陷(Bug)记录?
MYSQL08_子查询的概述、单行、多行、相关子查询
Peripheral driver library development notes 44:ddc114 ADC driver
According to the framework's swagger interface document
Distributed What index is high concurrency
分布式.CAP理论
Postgresql源码(64)查询执行——子模块Executor(2)执行前的数据结构和执行过程
Arduino I2C for TCA9548A应答扫描程序
[QNX hypervisor 2.2 user manual]8.6 interrupt
How to realize copyright protection of Digital Collections
What is gamefi?
MYSQL06_ Seven join operations and union all of sql99
kubernetes的这几种存储卷,别再傻傻分不清了
分布式.容量评估
[experience sharing] mathematical modeling paper format requirements and summary of common problems
[QT入门篇]定时器QTimer类
toast_tuple_threshold的疑问
JMeter学习笔记003-JMeter之CSV参数化
Top 10 NFTs at present
W10 system, how to adjust the application resolution