当前位置:网站首页>L1-003 single digit statistics
L1-003 single digit statistics
2022-07-21 19:23:00 【Alter_ r】
The original title is
Given a k An integer N=dk−110k−1+⋯+d1101+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 :
100311
sample output :
0:2
1:3
3:1
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[1010];// Single character array s
int a[10]={0};// initialization a The array is full of 0, Used to count the number of occurrences of each digit
int t = 0;
scanf("%s",s);
for(int i = 0; i < strlen(s); i++)//strlen(s) It's an array s The length of
{
t = s[i] - '0';//S[i] - '0' Change to an integer
a[t]++;
}
for(int i = 0; i < 10; i++)
{
if(a[i] != 0)
printf("%d:%d\n",i,a[i]);//a The subscript i Is the number that appears ,a[i] Is the number of occurrences
}
return 0;
}
边栏推荐
- FTP服务配置
- Web APIs DOM- 网页特效篇-元素大小和位置
- Force uninstall of additional domain controllers
- Distributed General service layer cache design
- Metahuman face shader summary
- How to solve the problem of unable to establish SSL connection in WGet command
- How to realize copyright protection of Digital Collections
- regular expression
- How to realize the data structure of nested tables in SQL
- Detailed explanation of at mode principle of Seata (3)
猜你喜欢
ThreadLocal
FTP service configuration
Sorting out of high-frequency interview questions, answers and knowledge context of Android, a major Internet company in 2022
建议收藏 | 可实操,数据中台选型示例
06 提取数据的json字符串
05 正则表达式语法
2022 software testing skills jmeter+ant+jenkins continuous integration and test report generation tutorial
Naixue's tea layout: how to transform the traditional brand of yuancosmos into yuancosmos marketing
【LeetCode】1260. 二维网格迁移
Distributed High concurrency concepts and design goals
随机推荐
Software testing interview question: software testing is divided into several stages. What are the testing strategies and requirements for each stage?
分布式.数据库架构
打造高性能应用,持续优化用户体验
China phosphorus pentachloride Market Research and investment forecast report (2022 Edition)
Distributed Base theory
分布式.BASE理论
[experience sharing] mathematical modeling paper format requirements and summary of common problems
FTP service configuration
05 regular expression syntax
plantuml画链路图
函数、方法和接口的区别
Distributed High concurrency & high availability
Distributed High availability and high scalability index
如何解决wget命令出现Unable to establish SSL connection.
Software testing interview questions: black box testing and white box testing are two basic methods of software testing. Please explain their advantages and disadvantages respectively!
Distributed load balancing
[information retrieval] implementation of information retrieval system
Spark RDD, application case of spark SQL
SAP smartforms 打印失败 消息类型:SSFCOMPOSER 消息号:601 (货币和数字字段设置参考及格式)
Ardunio development - I2C protocol communication - control 2x16lcd