当前位置:网站首页>Pat class B 1021 digit statistics
Pat class B 1021 digit statistics
2022-06-23 05:58:00 【Octopus bro】
1021. Single digit statistics (15)
Given a k An integer N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0), Please write a program to count the number of times each different digit number appears . for example : Given N = 100311, Then there are 2 individual 0,3 individual 1, and 1 individual 3.
Input format :
Each input contains 1 Test cases , I.e. no more than one 1000 Bit positive integer N.
Output format :
Yes N Each different digit in , With D:M Output the digit in one line D And in N Is the number of times M. Required press D Ascending output of .
sample input :100311sample output :
0:2 1:3 3:1
Ideas : The number of digits is too large , Only strings can be used , First initialize a file with a length of 10 The array of is used as the count array , The following table corresponds to numbers , For each bit of the input string -‘0’, Take the result of this operation as the array subscript plus one operation , Finally, output
One 、 Starting variable
1.input【1000】 Input string
2.count【10】 Count array
Two 、 operation
1. Input string
2. Subtract each bit of the input string ‘0’ operation ,
3. Take the result of the operation as the index of the count array to perform the plus one operation
4. Cyclic output
3、 ... and 、 Code
#include "stdio.h"
#include "string.h"
int main()
{
char input[1000];
memset(input,0,1000);
scanf("%s",input);
int i;
int count[10] = {0,0,0,0,0,0,0,0,0,0};// Corresponding 0-9 Number of occurrences of
for(i = 0; i < strlen(input); i++)
{
count[input[i] - '0']++;
}
for(i = 0; i < 10; i++)
{
if(count[i] != 0)
{
printf("%d:%d\n",i,count[i]);
}
}
return 0;
}边栏推荐
- jvm-05. garbage collection
- Real MySQL interview question (30) -- shell real estate order analysis
- Software design and Development Notes 2: serial port debugging tool based on QT design
- 三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
- 【斯坦福计网CS144项目】Lab2: TCPReceiver
- Explicability of counter attack based on optimal transmission theory
- 阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
- Explanation of penetration test process and methodology (Introduction to web security 04)
- 数字化工厂建设可划分为三个方面
- Ansible 使用普通用户管理被控端
猜你喜欢

jvm-04. Object's memory layout

jvm-06.垃圾回收器

Redis cache penetration solution - bloom filter

True MySQL interview question (21) - Finance - overdue loan

ssm项目搭建

Deploy docker and install MySQL in centos7

编址和编址单位

Opportunities and challenges of digital collections from the perspective of technology development team

ant使用总结(三):批量打包apk

数字藏品赋能实体产业释放了哪些利好?
随机推荐
PAT 乙等 1019 C语言
Pit filling for abandoned openssl-1.0.2 (.A to.So)
Visual Studio调试技巧
Work accumulation - judge whether GPS is on
制造业数字化转型存在问题及原因分析
Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
Android handler memory leak kotlin memory leak handling
PAT 乙等 1012 C语言
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
关于安装pip3 install chatterbot报错的问题
Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators
Explicability of counter attack based on optimal transmission theory
Basic calculator II for leetcode topic analysis
The digital collection market has just begun
Opportunities and challenges of digital collections from the perspective of technology development team
The traditional Internet like platform may no longer exist, and a new industry integrating industrial characteristics and Internet characteristics
The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet
vant weapp日历组件性能优化 Calendar 日历添加min-date最小日期页面加载缓慢
华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位