当前位置:网站首页>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;
}边栏推荐
- Real MySQL interview question (23) -- pinduoduo ball game analysis
- Wechat applet; AI intelligent dubbing assistant
- AHA C language Chapter 7 you can do more with it (talks 27-28)
- Explicability of counter attack based on optimal transmission theory
- The official artifact of station B has cracked itself!
- Pat class B 1011 C language
- Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration
- [Stanford Jiwang cs144 project] lab2: tcpreceiver
- The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming
- Activity启动模式和生命周期实测结果
猜你喜欢

A bit of knowledge - folding forging and Damascus steel
![[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale](/img/2d/96a370c90dcb7091038afad33bc4b4.png)
[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale

Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions

Arctime makes Chinese and English subtitle video

The construction of digital factory can be divided into three aspects

MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选
![[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code](/img/e2/24eb2a60e3dc603b3ec4bfefd0b8e5.png)
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code

MySQL面试真题(二十三)——拼多多-球赛分析

True MySQL interview question (24) -- row column exchange

Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration
随机推荐
Opportunities and challenges of digital collections from the perspective of technology development team
[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale
MySQL面试真题(二十四)——行列互换
Pat class B 1012 C language
PAT 乙等 1026 程序运行时间
C primer plus learning notes - 2. Constant and formatted IO (input / output)
PAT 乙等 1011 C语言
Prometheus, incluxdb2.2 installation and flume_ Export download compile use
Pit filling for abandoned openssl-1.0.2 (.A to.So)
Skill self check | do you know these 6 skills if you want to be a test leader?
Oracle exception
PAT 乙等 1010 C语言
Wechat applet; AI intelligent dubbing assistant
Excel sheet column title for leetcode Title Resolution
PAT 乙等 1024 科学记数法 C语言
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions
技能自检 | 想当测试Leader,这6项技能你会吗?
Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
jvm-02. Guarantee of orderliness
The difference between SaaS software and traditional software delivery mode